Changeset 807
- Timestamp:
- 08/13/07 18:16:16 (1 year ago)
- Files:
-
- trunk/config/xml/memphis.xml (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisConfig.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php (modified) (2 diffs)
- trunk/src/main/resources/xjconf/websites.xml (modified) (4 diffs)
- trunk/src/test/php/net/stubbles/integration/MemphisConfigTestCase.php (added)
- trunk/src/test/runIntegration.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/xml/memphis.xml
r803 r807 36 36 </frames> 37 37 <metaTags> 38 <meta name="description"> 1und1.de, das Portal für Produkte rund um das Internet. DSL, Webhosting, Mobiles Internet, Server und vieles mehr...</meta>39 <meta name="keywords"> 1&1, Webhosting, Domain, Puretec, 0700, Shop, Shops, surfen, Internet-Zugang, Internet, E-Mail, Outlook, Messaging, billig, schnell, günstig, DSL, ADSL, Netzanschluss, Flatrate, Hardware, Modem, Voip, Video-on-Demand, 3DSL, DSL2+, Server, Sofort-Start, AmericaŽs Cup, United Internet Team Germany, Postfach, Speicherplatz, Pocket Web, Mobiles Internet, Pocket-Web, Telefon-Flat, Flat, 16.000, Highspeed-Netzanschluss, 1und1, 1+1, E-Shops, SharePoint, Outlook, Exchange, Schlund, Schlund+Partner, S+P, Highspeed-Download, Upstream, Downstream, Fastpath, Ping, Homepage, Platin Service, Wunschdomain, Domaincheck, Verfügbarkeitscheck</meta>38 <meta name="description">This is a description.</meta> 39 <meta name="keywords">keyword1, keyword2</meta> 40 40 </metaTags> 41 41 </config> trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisConfig.php
r803 r807 14 14 * @subpackage websites_memphis 15 15 */ 16 class stubMemphisConfig extends stub BaseObject16 class stubMemphisConfig extends stubXJConfAbstractInitializer 17 17 { 18 18 /** 19 19 * holds the configuration data 20 20 * 21 * @var array 21 * @var array<string,mixed> 22 22 */ 23 23 protected $config; … … 32 32 public function __construct($cachePath = null, $configPath = null) 33 33 { 34 $cachePath = ((null == $cachePath) ? (stubConfig::getCachePath() . DIRECTORY_SEPARATOR) : ($cachePath)); 35 $configPath = ((null == $configPath) ? (stubConfig::getConfigPath() . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR) : ($configPath)); 36 $this->config = $this->getConfig($configPath, $cachePath); 34 $xjconfProxy = new stubXJConfProxy($this); 35 $xjconfProxy->process(); 37 36 if (isset($this->config['parts']) == false || count($this->config['parts']) == 0) { 38 37 throw new stubException('No parts configured.'); … … 45 44 46 45 /** 46 * returns the descriptor that identifies the initializer 47 * 48 * @param string $type type of descriptor: config or definition 49 * @return string 50 */ 51 public function getDescriptor($type) 52 { 53 return 'memphis'; 54 } 55 56 /** 57 * returns the data to cache 58 * 59 * @return array 60 */ 61 public function getCacheData() 62 { 63 $cacheData = array('classes' => array(), 'data' => serialize($this->config)); 64 foreach ($this->config['parts'] as $part) { 65 if (isset($part['defaultElements']) == false) { 66 continue; 67 } 68 69 foreach ($part['defaultElements'] as $defaultElement) { 70 $cacheData['classes'][] = $defaultElement->getClassName(); 71 foreach ($defaultElement->getRequiredClassNames() as $requiredClassName) { 72 $cacheData['classes'][] = $requiredClassName; 73 } 74 } 75 76 } 77 78 return $cacheData; 79 } 80 81 /** 82 * sets the data from the cache 83 * 84 * @param array $cacheData 85 */ 86 public function setCacheData(array $cacheData) 87 { 88 foreach ($cacheData['classes'] as $class) { 89 stubClassLoader::load($class); 90 } 91 92 $this->config = unserialize($cacheData['data']); 93 } 94 95 /** 96 * returns definitions that are additionally required beyond the default definition 97 * 98 * @return array<string> 99 */ 100 public function getAdditionalDefinitions() 101 { 102 return array('xjconf/websites.xml'); 103 } 104 105 /** 106 * will be called in case the stubXJConfProxy did not found the data in the 107 * cache and the initializer has to load values from the facade 108 * 109 * @param stubXJConfFacade $xjconf 110 */ 111 public function loadData(stubXJConfFacade $xjconf) 112 { 113 $this->config = $xjconf->getConfigValue('config'); 114 } 115 116 /** 47 117 * returns the list of parts 48 118 * … … 51 121 public function getParts() 52 122 { 53 return $this->config['parts']; 123 return array_keys($this->config['parts']); 124 } 125 126 /** 127 * returns a list of default elements for a part 128 * 129 * @param string $part 130 * @return array<stubPageElement> 131 */ 132 public function getDefaultElements($part) 133 { 134 if (isset($this->config['parts'][$part]) == true && isset($this->config['parts'][$part]['defaultElements']) == true) { 135 $this->config['parts'][$part]['defaultElements']; 136 } 137 138 return array(); 54 139 } 55 140 … … 86 171 return array(); 87 172 } 88 89 /**90 * returns the configuration91 *92 * @return array93 * @throws stubException94 */95 protected function getConfig($configPath, $cachePath)96 {97 $cacheSource = $cachePath . 'memphis.cache';98 $configSource = $configPath . 'memphis.xml';99 if (file_exists($cacheSource) && filemtime($cacheSource) >= filemtime($configSource)) {100 $cacheData = unserialize(file_get_contents($cacheSource));101 foreach ($cacheData['classes'] as $class) {102 stubClassLoader::load($class);103 }104 105 $config = unserialize($cacheData['data']);106 return $config;107 }108 109 $config = $this->getFromXJConf($configSource);110 $cacheData = array('classes' => array(), 'data' => serialize($config));111 foreach ($config['parts'] as $part) {112 if (isset($part['defaultElements']) == false) {113 continue;114 }115 116 foreach ($part['defaultElements'] as $defaultElement) {117 $cacheData['classes'][] = $defaultElement->getClassName();118 foreach ($defaultElement->getRequiredClassNames() as $requiredClassName) {119 $cacheData['classes'][] = $requiredClassName;120 }121 }122 123 }124 125 if (file_exists(dirname($cacheSource)) == false) {126 mkdir(dirname($cacheSource), 0700, true);127 }128 129 file_put_contents($cacheSource, serialize($cacheData));130 return $config;131 }132 133 /**134 * returns the configured stubPage instance135 *136 * @param string $configSource source of the page configuration to use137 * @return array138 * @throws stubException139 */140 protected function getFromXJConf($configSource)141 {142 stubClassLoader::load('net.stubbles.util.stubFactory',143 'net.stubbles.util.xjconf.xjconfReal'144 );145 $xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance())));146 $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/websites.xml'));147 $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/memphis.xml'));148 $xjconf->addExtension(new stubConfigXJConfExtension());149 150 try {151 $xjconf->parse($configSource);152 return $xjconf->getConfigValue('config');153 } catch (stubXJConfException $xjce) {154 throw new stubException('Can not read configuration from ' . $configSource, $xjce);155 }156 }157 173 } 158 174 ?> trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php
r803 r807 46 46 { 47 47 parent::__construct($request, $session, $response, $pageFactory); 48 $this->config = new stubMemphisConfig(); 49 $this->template = new stubMemphisTemplate(); 48 $this->config = $this->createConfig(); 49 $this->template = $this->createTemplate(); 50 } 51 52 /** 53 * helper method to create the config object 54 * 55 * @return stubMemphisConfig 56 */ 57 protected function createConfig() 58 { 59 return new stubMemphisConfig(); 60 } 61 62 /** 63 * helper method to create the template 64 * 65 * @return stubMemphisTemplate 66 */ 67 protected function createTemplate() 68 { 69 return new stubMemphisTemplate(); 50 70 } 51 71 … … 66 86 $content = array(); 67 87 $context = array('part' => null, 68 'tmpl' => $this->template 88 'tmpl' => $this->template, 89 'page' => $page 69 90 ); 70 91 71 92 $this->template->readTemplatesFromFile($this->config->getFrame($this->getFrameId($page))); 72 93 $this->setTemplateVars($page); 73 $parts = $this->config->getParts(); 74 foreach (array_keys($parts) as $part) { 94 foreach ($this->config->getParts() as $part) { 75 95 $content = ''; 76 96 $context['part'] = $part; 77 if (isset($parts[$part]['defaultElements']) == true) { 78 foreach ($parts[$part]['defaultElements'] as $defaultElement) { 79 $prefixRequest->setPrefix($defaultElement->getName()); 80 $content .= $this->processElement($defaultElement, $prefixRequest, $context); 81 } 97 foreach ($this->config->getDefaultElements($part) as $defaultElement) { 98 $prefixRequest->setPrefix($defaultElement->getName()); 99 $content .= $this->processElement($defaultElement, $prefixRequest, $context); 82 100 } 83 101 trunk/src/main/resources/xjconf/websites.xml
r803 r807 12 12 <tag name="property" type="string" keyAttribute="name" /> 13 13 14 <abstractTag name="element" abstractType="net.stubbles.websites.stubPageElement" concreteTypeAttribute="type" setter="addElement" >14 <abstractTag name="element" abstractType="net.stubbles.websites.stubPageElement" concreteTypeAttribute="type" setter="addElement" key="__none"> 15 15 <attribute name="name" type="string" /> 16 16 </abstractTag> 17 17 18 18 <!-- Memphis --> 19 <abstractTag name="memphisElement" extends="element" abstractType="net.stubbles.websites.memphis.stubMemphisPageElement" concreteTypeAttribute="type" setter="addElement" >19 <abstractTag name="memphisElement" extends="element" abstractType="net.stubbles.websites.memphis.stubMemphisPageElement" concreteTypeAttribute="type" setter="addElement" key="__none"> 20 20 <attribute name="parts" type="string" /> 21 21 </abstractTag> 22 22 23 <tag name="includeFile" extends="memphisElement" type="net.stubbles.websites.memphis.stubMemphisIncludeFilePageElement" setter="addElement" >23 <tag name="includeFile" extends="memphisElement" type="net.stubbles.websites.memphis.stubMemphisIncludeFilePageElement" setter="addElement" key="__none"> 24 24 <attribute name="source" type="string" /> 25 25 </tag> 26 26 27 <!--tag name="includeTemplate" extends="memphisElement" type="net.stubbles.websites.memphis.stubMemphisIncludeTemplatePageElement" setter="addElement" >27 <!--tag name="includeTemplate" extends="memphisElement" type="net.stubbles.websites.memphis.stubMemphisIncludeTemplatePageElement" setter="addElement" key="__none"> 28 28 <attribute name="source" type="string" /> 29 29 </tag> 30 30 31 <tag name="loadExtension" extends="memphisElement" type="net.stubbles.websites.memphis.stubMemphisLoadExtensionPageElement" setter="addElement" >31 <tag name="loadExtension" extends="memphisElement" type="net.stubbles.websites.memphis.stubMemphisLoadExtensionPageElement" setter="addElement" key="__none"> 32 32 <attribute name="extension" type="string" /> 33 33 </tag--> … … 39 39 40 40 <!-- XML/XSL --> 41 <abstractTag name="xmlElement" extends="element" abstractType="net.stubbles.websites.xml.stubXMLPageElement" concreteTypeAttribute="type" setter="addElement" />41 <abstractTag name="xmlElement" extends="element" abstractType="net.stubbles.websites.xml.stubXMLPageElement" concreteTypeAttribute="type" setter="addElement" key="__none" /> 42 42 43 <tag name="xmlPassThru" extends="xmlElement" type="net.stubbles.websites.xml.stubXMLPassThruPageElement" setter="addElement" >43 <tag name="xmlPassThru" extends="xmlElement" type="net.stubbles.websites.xml.stubXMLPassThruPageElement" setter="addElement" key="__none"> 44 44 <attribute name="directory" type="string"/> 45 45 <attribute name="fileName" type="string"/> … … 47 47 48 48 <!-- Decorators --> 49 <abstractTag name="xmlElementDecorator" abstractType="net.stubbles.websites.xml.stubXMLPageElement" concreteTypeAttribute="type" setter="addElement" >49 <abstractTag name="xmlElementDecorator" abstractType="net.stubbles.websites.xml.stubXMLPageElement" concreteTypeAttribute="type" setter="addElement" key="__none"> 50 50 <constructor> 51 51 <child name="xmlElement"/> … … 53 53 </abstractTag> 54 54 55 <tag name="xmlElementCachingDecorator" extends="xmlElementDecorator" type="net.stubbles.websites.xml.stubXMLPageElementCachingDecorator" setter="addElement" >55 <tag name="xmlElementCachingDecorator" extends="xmlElementDecorator" type="net.stubbles.websites.xml.stubXMLPageElementCachingDecorator" setter="addElement" key="__none"> 56 56 <attribute name="lifetime" type="int"/> 57 57 </tag> trunk/src/test/runIntegration.php
r742 r807 36 36 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/InterceptorTestCase.php'); 37 37 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/LoggerTestCase.php'); 38 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/MemphisConfigTestCase.php'); 38 39 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/ProcessorTestCase.php'); 39 40 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/RegistryTestCase.php');
