Changeset 1113
- Timestamp:
- 12/05/07 16:48:38 (9 months ago)
- Files:
-
- trunk/config/xml/memphis.xml (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisAbstractExtension.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisExtension.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeFilePageElement.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeTemplatePageElement.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisLoadExtensionPageElement.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/stubAbstractPageElement.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/stubPageElement.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementCachingDecorator.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementDecorator.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPassThruPageElement.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/integration/MemphisConfigTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisIncludeFilePageElementTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/xml/memphis.xml
r807 r1113 9 9 <part name="navteasers"> 10 10 <defaultElements> 11 <ws:includeFile name="acup" source="content /navteaser/acup.html">11 <ws:includeFile name="acup" source="contentFile.txt"> 12 12 <!--ws:conditions> 13 13 <ws:condition type="net.stubbles.websites.memphis.conditions.stubMemphisPageElementExcludePagesCondition" value="jobs_*, press_*, acup, hilfe-kontakt, faq, beratung"/> 14 14 </ws:conditions--> 15 15 </ws:includeFile> 16 <ws:includeFile name="search" source="content /navteaser/suche.html">16 <ws:includeFile name="search" source="contentFile.txt"> 17 17 <!--ws:conditions> 18 18 <ws:condition type="net.stubbles.websites.memphis.conditions.stubMemphisPageElementExcludePagesCondition" value="suche"/> trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisAbstractExtension.php
r963 r1113 67 67 $this->context = $context; 68 68 } 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 } 69 89 } 70 90 ?> trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisExtension.php
r946 r1113 36 36 37 37 /** 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 /** 38 52 * processes the work within the extension 39 53 */ trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeFilePageElement.php
r1110 r1113 7 7 * @subpackage websites_memphis 8 8 */ 9 stubClassLoader::load('net.stubbles.lang.exceptions.stub IOException',9 stubClassLoader::load('net.stubbles.lang.exceptions.stubFileNotFoundException', 10 10 'net.stubbles.util.stubRegistry', 11 11 'net.stubbles.websites.memphis.stubMemphisPageElement' … … 24 24 * @var string 25 25 */ 26 protected $source = '';26 protected $source = null; 27 27 /** 28 28 * base directory where content is located … … 37 37 public static function __static() 38 38 { 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'); 40 40 } 41 41 … … 43 43 * set the source of the element 44 44 * 45 * @param string $source 45 * @param string $source 46 * @throws stubFileNotFoundException 46 47 */ 47 48 public function setSource($source) 48 49 { 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)); 50 56 } 51 57 … … 61 67 62 68 /** 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 /** 63 89 * processes the page element 64 90 * 65 91 * @return string 66 * @throws stubIOException67 92 */ 68 93 public function process() 69 94 { 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) { 76 96 return file_get_contents($this->source); 77 97 } 78 98 79 return file_get_contents(self::$baseDir . DIRECTORY_SEPARATOR . $this->source);99 return ''; 80 100 } 81 101 } trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeTemplatePageElement.php
r1110 r1113 7 7 * @subpackage websites_memphis 8 8 */ 9 stubClassLoader::load('net.stubbles.lang.exceptions.stubIOException', 10 'net.stubbles.websites.memphis.stubMemphisPageElement', 11 'net.stubbles.websites.memphis.stubMemphisTemplate' 9 stubClassLoader::load('net.stubbles.lang.exceptions.stubFileNotFoundException', 10 'net.stubbles.websites.memphis.stubMemphisPageElement' 12 11 ); 13 12 /** … … 25 24 */ 26 25 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 } 27 40 28 41 /** 29 42 * set the source of the element 30 43 * 31 * @param string $source 44 * @param string $source 45 * @throws stubFileNotFoundException 32 46 */ 33 47 public function setSource($source) 34 48 { 49 if (file_exists(self::$tmplPath . DIRECTORY_SEPARATOR . $source) == false) { 50 throw new stubFileNotFoundException(self::$tmplPath . DIRECTORY_SEPARATOR . $source); 51 } 52 35 53 $this->source = $source; 36 54 } … … 47 65 48 66 /** 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 /** 49 87 * processes the page element 50 88 * 51 89 * @return string 52 * @throws stubIOException53 90 */ 54 91 public function process() 55 92 { 56 93 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'); 63 95 } 64 96 trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisLoadExtensionPageElement.php
r1110 r1113 9 9 stubClassLoader::load('net.stubbles.lang.exceptions.stubIOException', 10 10 'net.stubbles.ioc.stubBinder', 11 'net.stubbles.reflection.stubReflectionClass',12 11 'net.stubbles.websites.memphis.stubMemphisExtension', 13 'net.stubbles.websites.memphis.stubMemphisPageElement', 14 'net.stubbles.websites.memphis.stubMemphisTemplate' 12 'net.stubbles.websites.memphis.stubMemphisPageElement' 15 13 ); 16 14 /** … … 23 21 { 24 22 /** 25 * extension class 23 * extension class name 26 24 * 27 25 * @var string 28 26 */ 29 27 protected $fqClassName = ''; 28 /** 29 * extension instance 30 * 31 * @var stubMemphisExtension 32 */ 33 protected $extension; 30 34 31 35 /** … … 50 54 51 55 /** 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 /** 52 106 * processes the page element 53 107 * 54 108 * @return string 55 * @throws stubIOException56 109 */ 57 110 public function process() 58 111 { 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 } 72 114 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 }78 115 } 79 116 ?> trunk/src/main/php/net/stubbles/websites/stubAbstractPageElement.php
r1110 r1113 102 102 return true; 103 103 } 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 } 104 124 } 105 125 ?> trunk/src/main/php/net/stubbles/websites/stubPageElement.php
r1110 r1113 59 59 60 60 /** 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 /** 61 75 * processes the page element 62 76 * trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementCachingDecorator.php
r1110 r1113 35 35 36 36 /** 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 /** 37 47 * Tries to load the result from the cache or processes the page element. 38 48 * trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementDecorator.php
r1110 r1113 115 115 116 116 /** 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 /** 117 137 * processes the page element 118 138 * trunk/src/main/php/net/stubbles/websites/xml/stubXMLPassThruPageElement.php
r1110 r1113 70 70 71 71 /** 72 * returns a list of form values72 * returns a list of variables that have an influence on caching 73 73 * 74 * @return array<string,string> 75 * @XMLIgnore() 74 * @return array<string,scalar> 76 75 */ 77 public function get FormValues()76 public function getCacheVars() 78 77 { 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); 80 89 } 81 90 … … 90 99 return $this; 91 100 } 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 } 92 112 } 93 113 ?> trunk/src/test/php/net/stubbles/integration/MemphisConfigTestCase.php
r807 r1113 21 21 public function testConfig() 22 22 { 23 stubRegistry::setConfig('net.stubbles.websites.memphis.templateDir', TEST_SRC_PATH . DIRECTORY_SEPARATOR . 'resources'); 23 24 $memphisConfig = new stubMemphisConfig(); 24 25 $this->assertEqual($memphisConfig->getParts(), array('content', 'navteasers', 'teasers', 'annotations', 'header')); trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisIncludeFilePageElementTestCase.php
r1110 r1113 47 47 { 48 48 $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'); 51 53 } 52 54 … … 59 61 $this->assertEqual($this->includeFilePageElement->process(), 'This is the content.'); 60 62 } 61 62 /**63 * assure that processing works as expected64 */65 public function testProcessNonExistingIncludeFile()66 {67 $this->includeFilePageElement->setSource(TEST_SRC_PATH . '/resources/doesNotExist');68 $this->expectException('stubException');69 $this->includeFilePageElement->process();70 }71 63 } 72 64 ?>
