Changeset 1113

Show
Ignore:
Timestamp:
12/05/07 16:48:38 (9 months ago)
Author:
mikey
Message:

made page elements and extensions ready for working together with website cache (part of enhancement #116)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/xml/memphis.xml

    r807 r1113  
    99      <part name="navteasers"> 
    1010        <defaultElements> 
    11           <ws:includeFile name="acup" source="content/navteaser/acup.html"> 
     11          <ws:includeFile name="acup" source="contentFile.txt"> 
    1212            <!--ws:conditions> 
    1313              <ws:condition type="net.stubbles.websites.memphis.conditions.stubMemphisPageElementExcludePagesCondition" value="jobs_*, press_*, acup, hilfe-kontakt, faq, beratung"/> 
    1414            </ws:conditions--> 
    1515          </ws:includeFile> 
    16           <ws:includeFile name="search" source="content/navteaser/suche.html"> 
     16          <ws:includeFile name="search" source="contentFile.txt"> 
    1717            <!--ws:conditions> 
    1818              <ws:condition type="net.stubbles.websites.memphis.conditions.stubMemphisPageElementExcludePagesCondition" value="suche"/> 
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisAbstractExtension.php

    r963 r1113  
    6767        $this->context = $context; 
    6868    } 
     69 
     70    /** 
     71     * returns a list of variables that have an influence on caching 
     72     * 
     73     * @return  array<string,scalar> 
     74     */ 
     75    public function getCacheVars() 
     76    { 
     77        return array(); 
     78    } 
     79 
     80    /** 
     81     * returns a list of files used to create the content 
     82     * 
     83     * @return  array<string> 
     84     */ 
     85    public function getUsedFiles() 
     86    { 
     87        return array(); 
     88    } 
    6989} 
    7090?> 
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisExtension.php

    r946 r1113  
    3636 
    3737    /** 
     38     * returns a list of variables that have an influence on caching 
     39     * 
     40     * @return  array<string,scalar> 
     41     */ 
     42    public function getCacheVars(); 
     43 
     44    /** 
     45     * returns a list of files used to create the content 
     46     * 
     47     * @return  array<string> 
     48     */ 
     49    public function getUsedFiles(); 
     50 
     51    /** 
    3852     * processes the work within the extension 
    3953     */ 
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeFilePageElement.php

    r1110 r1113  
    77 * @subpackage  websites_memphis 
    88 */ 
    9 stubClassLoader::load('net.stubbles.lang.exceptions.stubIOException', 
     9stubClassLoader::load('net.stubbles.lang.exceptions.stubFileNotFoundException', 
    1010                      'net.stubbles.util.stubRegistry', 
    1111                      'net.stubbles.websites.memphis.stubMemphisPageElement' 
     
    2424     * @var  string 
    2525     */ 
    26     protected $source = ''
     26    protected $source = null
    2727    /** 
    2828     * base directory where content is located 
     
    3737    public static function __static() 
    3838    { 
    39         self::$baseDir = stubRegistry::getConfig('net.stubbles.websites.memphis.templateDir', stubConfig::getPagePath() . '/../templates'); 
     39        self::$baseDir = stubRegistry::getConfig('net.stubbles.websites.memphis.templateDir', stubConfig::getPagePath() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates'); 
    4040    } 
    4141 
     
    4343     * set the source of the element 
    4444     * 
    45      * @param  string  $source 
     45     * @param   string  $source 
     46     * @throws  stubFileNotFoundException 
    4647     */ 
    4748    public function setSource($source) 
    4849    { 
    49         $this->source = $source; 
     50        $existsInBasePath = file_exists(self::$baseDir . DIRECTORY_SEPARATOR . $source); 
     51        if (false === $existsInBasePath && file_exists($source) === false) { 
     52            throw new stubFileNotFoundException($source); 
     53        } 
     54         
     55        $this->source = ((false === $existsInBasePath) ? ($source) : (self::$baseDir . DIRECTORY_SEPARATOR . $source)); 
    5056    } 
    5157 
     
    6167 
    6268    /** 
     69     * returns a list of variables that have an influence on caching 
     70     * 
     71     * @return  array<string,scalar> 
     72     */ 
     73    public function getCacheVars() 
     74    { 
     75        return array('source' => $this->source); 
     76    } 
     77 
     78    /** 
     79     * returns a list of files used to create the content 
     80     * 
     81     * @return  array<string> 
     82     */ 
     83    public function getUsedFiles() 
     84    { 
     85        return array($this->source); 
     86    } 
     87 
     88    /** 
    6389     * processes the page element 
    6490     * 
    6591     * @return  string 
    66      * @throws  stubIOException 
    6792     */ 
    6893    public function process() 
    6994    { 
    70         $existsInBasePath = file_exists(self::$baseDir . DIRECTORY_SEPARATOR . $this->source); 
    71         if (false === $existsInBasePath && file_exists($this->source) === false) { 
    72             throw new stubIOException('The file ' . $this->source . ' does not exist or could not be read.'); 
    73         } 
    74          
    75         if (false === $existsInBasePath) { 
     95        if (null !== $this->source) { 
    7696            return file_get_contents($this->source); 
    7797        } 
    7898         
    79         return file_get_contents(self::$baseDir . DIRECTORY_SEPARATOR . $this->source)
     99        return ''
    80100    } 
    81101} 
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeTemplatePageElement.php

    r1110 r1113  
    77 * @subpackage  websites_memphis 
    88 */ 
    9 stubClassLoader::load('net.stubbles.lang.exceptions.stubIOException', 
    10                       'net.stubbles.websites.memphis.stubMemphisPageElement', 
    11                       'net.stubbles.websites.memphis.stubMemphisTemplate' 
     9stubClassLoader::load('net.stubbles.lang.exceptions.stubFileNotFoundException', 
     10                      'net.stubbles.websites.memphis.stubMemphisPageElement' 
    1211); 
    1312/** 
     
    2524     */ 
    2625    protected $source = ''; 
     26    /** 
     27     * base directory where content is located 
     28     * 
     29     * @var  string 
     30     */ 
     31    protected static $tmplPath; 
     32 
     33    /** 
     34     * static initializing 
     35     */ 
     36    public static function __static() 
     37    { 
     38        self::$tmplPath = stubRegistry::getConfig('net.stubbles.websites.memphis.templateDir', stubConfig::getPagePath() . '/../templates'); 
     39    } 
    2740 
    2841    /** 
    2942     * set the source of the element 
    3043     * 
    31      * @param  string  $source 
     44     * @param   string  $source 
     45     * @throws  stubFileNotFoundException 
    3246     */ 
    3347    public function setSource($source) 
    3448    { 
     49        if (file_exists(self::$tmplPath . DIRECTORY_SEPARATOR . $source) == false) { 
     50            throw new stubFileNotFoundException(self::$tmplPath . DIRECTORY_SEPARATOR . $source); 
     51        } 
     52         
    3553        $this->source = $source; 
    3654    } 
     
    4765 
    4866    /** 
     67     * returns a list of variables that have an influence on caching 
     68     * 
     69     * @return  array<string,scalar> 
     70     */ 
     71    public function getCacheVars() 
     72    { 
     73        return array('source' => $this->source); 
     74    } 
     75 
     76    /** 
     77     * returns a list of files used to create the content 
     78     * 
     79     * @return  array<string> 
     80     */ 
     81    public function getUsedFiles() 
     82    { 
     83        return array(self::$tmplPath . DIRECTORY_SEPARATOR . $this->source); 
     84    } 
     85 
     86    /** 
    4987     * processes the page element 
    5088     * 
    5189     * @return  string 
    52      * @throws  stubIOException 
    5390     */ 
    5491    public function process() 
    5592    { 
    5693        if (isset($this->context['template']) === false || ($this->context['template'] instanceof stubMemphisTemplate) === false) { 
    57             throw new stubRuntimeException('Context contains no template of instance net.stubbles.websites.memphis.stubMemphisTemplate'); 
    58         } 
    59          
    60         $tmplPath = stubRegistry::getConfig('net.stubbles.websites.memphis.templateDir', stubConfig::getPagePath() . '/../templates'); 
    61         if (file_exists($tmplPath . '/' . $this->source) == false) { 
    62             throw new stubIOException('The template ' . $tmplPath . '/' . $this->source . ' does not exist or could not be read.'); 
     94            throw new stubRuntimeException('Context contains no template of instance net::stubbles::websites::memphis::stubMemphisTemplate'); 
    6395        } 
    6496         
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisLoadExtensionPageElement.php

    r1110 r1113  
    99stubClassLoader::load('net.stubbles.lang.exceptions.stubIOException', 
    1010                      'net.stubbles.ioc.stubBinder', 
    11                       'net.stubbles.reflection.stubReflectionClass', 
    1211                      'net.stubbles.websites.memphis.stubMemphisExtension', 
    13                       'net.stubbles.websites.memphis.stubMemphisPageElement', 
    14                       'net.stubbles.websites.memphis.stubMemphisTemplate' 
     12                      'net.stubbles.websites.memphis.stubMemphisPageElement' 
    1513); 
    1614/** 
     
    2321{ 
    2422    /** 
    25      * extension class 
     23     * extension class name 
    2624     * 
    2725     * @var  string 
    2826     */ 
    2927    protected $fqClassName = ''; 
     28    /** 
     29     * extension instance 
     30     * 
     31     * @var  stubMemphisExtension 
     32     */ 
     33    protected $extension; 
    3034 
    3135    /** 
     
    5054 
    5155    /** 
     56     * initializes the page element 
     57     * 
     58     * @param   stubRequest          $request   the request data 
     59     * @param   stubSession          $session   current session 
     60     * @param   stubResponse         $response  contains response data 
     61     * @param   array<string,mixed>  $context   optional  additional context data 
     62     */ 
     63    public function init(stubRequest $request, stubSession $session, stubResponse $response, array $context = array()) 
     64    { 
     65        parent::init($request, $session, $response, $context); 
     66        if (null === $this->extension) { 
     67            $binder = stubRegistry::get(stubBinder::REGISTRY_KEY); 
     68            if (($binder instanceof stubBinder) === false) { 
     69                throw new stubRuntimeException('No instance of net::stubbles::ioc::stubBinder in registry.'); 
     70            } 
     71             
     72            $binder->bindConstant()->named('context')->to($this->context); 
     73            $binder->bind('stubRequest')->named('prefixed')->toInstance($this->request); 
     74            $extension = $binder->getInjector()->getInstance($this->fqClassName); 
     75            if (($extension instanceof stubMemphisExtension) === false) { 
     76                throw new stubRuntimeException('Configured extension class ' . $class->getFullQualifiedClassName() . ' does not implement interface net.stubbles.websites.memphis.stubMemphisExtension.'); 
     77            } 
     78             
     79            $this->extension = $extension; 
     80        } else { 
     81            $this->extension->setContext($context); 
     82        } 
     83    } 
     84 
     85    /** 
     86     * returns a list of variables that have an influence on caching 
     87     * 
     88     * @return  array<string,scalar> 
     89     */ 
     90    public function getCacheVars() 
     91    { 
     92        return $this->extension->getCacheVars(); 
     93    } 
     94 
     95    /** 
     96     * returns a list of files used to create the content 
     97     * 
     98     * @return  array<string> 
     99     */ 
     100    public function getUsedFiles() 
     101    { 
     102        return $this->extension->getUsedFiles(); 
     103    } 
     104 
     105    /** 
    52106     * processes the page element 
    53107     * 
    54108     * @return  string 
    55      * @throws  stubIOException 
    56109     */ 
    57110    public function process() 
    58111    { 
    59         if (isset($this->context['template']) === false || ($this->context['template'] instanceof stubMemphisTemplate) === false) { 
    60             throw new stubRuntimeException('Context contains no template of instance net.stubbles.websites.memphis.stubMemphisTemplate'); 
    61         } 
    62          
    63         $class = new stubReflectionClass($this->fqClassName); 
    64         if ($class->implementsInterface('stubMemphisExtension') == false) { 
    65             throw new stubRuntimeException('Configured extension class ' . $class->getFullQualifiedClassName() . ' does not implement interface net.stubbles.websites.memphis.stubMemphisExtension.'); 
    66         } 
    67          
    68         $binder = stubRegistry::get('net.stubbles.ioc.stubBinder'); 
    69         if (($binder instanceof stubBinder) === false) { 
    70             throw new stubRuntimeException('No instance of net.stubbles.ioc.stubBinder in registry.'); 
    71         } 
     112        return $this->extension->process(); 
     113    } 
    72114 
    73         $binder->bindConstant()->named('context')->to($this->context); 
    74         $binder->bind('stubRequest')->named('prefixed')->toInstance($this->request); 
    75         $extension = $binder->getInjector()->getInstance($class->getName()); 
    76         return $extension->process(); 
    77     } 
    78115} 
    79116?> 
  • trunk/src/main/php/net/stubbles/websites/stubAbstractPageElement.php

    r1110 r1113  
    102102        return true; 
    103103    } 
     104 
     105    /** 
     106     * returns a list of variables that have an influence on caching 
     107     * 
     108     * @return  array<string,scalar> 
     109     */ 
     110    public function getCacheVars() 
     111    { 
     112        return array(); 
     113    } 
     114 
     115    /** 
     116     * returns a list of files used to create the content 
     117     * 
     118     * @return  array<string> 
     119     */ 
     120    public function getUsedFiles() 
     121    { 
     122        return array(); 
     123    } 
    104124} 
    105125?> 
  • trunk/src/main/php/net/stubbles/websites/stubPageElement.php

    r1110 r1113  
    5959 
    6060    /** 
     61     * returns a list of variables that have an influence on caching 
     62     * 
     63     * @return  array<string,scalar> 
     64     */ 
     65    public function getCacheVars(); 
     66 
     67    /** 
     68     * returns a list of files used to create the content 
     69     * 
     70     * @return  array<string> 
     71     */ 
     72    public function getUsedFiles(); 
     73 
     74    /** 
    6175     * processes the page element 
    6276     * 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementCachingDecorator.php

    r1110 r1113  
    3535 
    3636    /** 
     37     * returns a list of variables that have an influence on caching 
     38     * 
     39     * @return  array<string,scalar> 
     40     */ 
     41    public function getCacheVars() 
     42    { 
     43        return array('time' => time()); 
     44    } 
     45 
     46    /** 
    3747     * Tries to load the result from the cache or processes the page element. 
    3848     * 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementDecorator.php

    r1110 r1113  
    115115 
    116116    /** 
     117     * returns a list of variables that have an influence on caching 
     118     * 
     119     * @return  array<string,scalar> 
     120     */ 
     121    public function getCacheVars() 
     122    { 
     123        return $this->element->getCacheVars(); 
     124    } 
     125 
     126    /** 
     127     * returns a list of files used to create the content 
     128     * 
     129     * @return  array<string> 
     130     */ 
     131    public function getUsedFiles() 
     132    { 
     133        return $this->element->getUsedFiles(); 
     134    } 
     135 
     136    /** 
    117137     * processes the page element 
    118138     * 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLPassThruPageElement.php

    r1110 r1113  
    7070 
    7171    /** 
    72      * returns a list of form values 
     72     * returns a list of variables that have an influence on caching 
    7373     * 
    74      * @return  array<string,string> 
    75      * @XMLIgnore() 
     74     * @return  array<string,scalar> 
    7675     */ 
    77     public function getFormValues() 
     76    public function getCacheVars() 
    7877    { 
    79         return array(); 
     78        return array('filename' => $this->fileName); 
     79    } 
     80 
     81    /** 
     82     * returns a list of files used to create the content 
     83     * 
     84     * @return  array<string> 
     85     */ 
     86    public function getUsedFiles() 
     87    { 
     88        return array($this->directory . DIRECTORY_SEPARATOR . $this->fileName); 
    8089    } 
    8190 
     
    9099        return $this; 
    91100    } 
     101 
     102    /** 
     103     * returns a list of form values 
     104     * 
     105     * @return  array<string,string> 
     106     * @XMLIgnore() 
     107     */ 
     108    public function getFormValues() 
     109    { 
     110        return array(); 
     111    } 
    92112} 
    93113?> 
  • trunk/src/test/php/net/stubbles/integration/MemphisConfigTestCase.php

    r807 r1113  
    2121    public function testConfig() 
    2222    { 
     23        stubRegistry::setConfig('net.stubbles.websites.memphis.templateDir', TEST_SRC_PATH . DIRECTORY_SEPARATOR . 'resources'); 
    2324        $memphisConfig = new stubMemphisConfig(); 
    2425        $this->assertEqual($memphisConfig->getParts(), array('content', 'navteasers', 'teasers', 'annotations', 'header')); 
  • trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisIncludeFilePageElementTestCase.php

    r1110 r1113  
    4747    { 
    4848        $this->assertEqual($this->includeFilePageElement->getSource(), ''); 
    49         $this->includeFilePageElement->setSource('foo'); 
    50         $this->assertEqual($this->includeFilePageElement->getSource(), 'foo'); 
     49        $this->includeFilePageElement->setSource(TEST_SRC_PATH . '/resources/contentFile.txt'); 
     50        $this->assertEqual($this->includeFilePageElement->getSource(), TEST_SRC_PATH . '/resources/contentFile.txt'); 
     51        $this->expectException('stubFileNotFoundException'); 
     52        $this->includeFilePageElement->setSource(TEST_SRC_PATH . '/resources/doesNotExist'); 
    5153    } 
    5254 
     
    5961        $this->assertEqual($this->includeFilePageElement->process(), 'This is the content.'); 
    6062    } 
    61  
    62     /** 
    63      * assure that processing works as expected 
    64      */ 
    65     public function testProcessNonExistingIncludeFile() 
    66     { 
    67         $this->includeFilePageElement->setSource(TEST_SRC_PATH . '/resources/doesNotExist'); 
    68         $this->expectException('stubException'); 
    69         $this->includeFilePageElement->process(); 
    70     } 
    7163} 
    7264?>