Changeset 589
- Timestamp:
- 04/20/07 17:32:21 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/stubAbstractPageElement.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/stubPage.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/stubPageElement.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementDecorator.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/integration/stubPageXJConfFactoryTestCase.php (added)
- trunk/src/test/runIntegration.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/stubAbstractPageElement.php
r317 r589 42 42 return $this->name; 43 43 } 44 44 45 /** 46 * returns a list of required class names 47 * 48 * @return array<string> 49 */ 50 public function getRequiredClassNames() 51 { 52 return array(); 53 } 54 45 55 /** 46 56 * checks whether the page element is available or not trunk/src/main/php/net/stubbles/websites/stubPage.php
r277 r589 89 89 * returns the list of elements 90 90 * 91 * @return unknown91 * @return array<string,stubPageElement> 92 92 */ 93 93 public function getElements() trunk/src/main/php/net/stubbles/websites/stubPageElement.php
r317 r589 17 17 * @subpackage websites 18 18 */ 19 interface stubPageElement 19 interface stubPageElement extends stubObject 20 20 { 21 21 /** … … 32 32 */ 33 33 public function getName(); 34 34 35 /** 36 * returns a list of required class names 37 * 38 * @return array<string> 39 */ 40 public function getRequiredClassNames(); 41 35 42 /** 36 43 * checks whether the page element is available or not trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php
r580 r589 7 7 * @subpackage websites 8 8 */ 9 stubClassLoader::load('net.stubbles.util.stubFactory', 10 'net.stubbles.util.xjconf.xjconf', 11 'net.stubbles.util.xjconf.xjconfReal', 9 stubClassLoader::load('net.stubbles.util.xjconf.xjconf', 12 10 'net.stubbles.websites.stubPageConfigurationException', 13 11 'net.stubbles.websites.stubPageFactory' … … 27 25 */ 28 26 private static $xjconf; 27 /** 28 * path to cache files 29 * 30 * @var string 31 */ 32 protected $cachePath; 33 /** 34 * path to config files 35 * 36 * @var string 37 */ 38 protected $configPath; 29 39 30 40 /** 31 41 * constructor 42 * 43 * @param string $cachePath optional path to cache files 44 * @param string $configPath optional path to config files 32 45 */ 33 public function __construct( )46 public function __construct($cachePath = null, $configPath = null) 34 47 { 35 if (null == self::$xjconf) { 36 self::$xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 37 self::$xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/websites.xml')); 38 } 48 $this->cachePath = ((null == $cachePath) ? (stubConfig::getCachePath() . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR) : ($cachePath)); 49 $this->configPath = ((null == $configPath) ? (stubConfig::getConfigPath() . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR) : ($configPath)); 39 50 } 40 51 41 52 /** 42 53 * checks whether the page factory knows the page or not … … 47 58 public function hasPage($configSource) 48 59 { 49 return file_exists( stubConfig::getConfigPath() . '/xml/pages/'. $configSource . '.xml');60 return file_exists($this->configPath . $configSource . '.xml'); 50 61 } 51 62 … … 59 70 public function getPage($configSource) 60 71 { 61 $configSource = stubConfig::getConfigPath() . '/xml/pages/' . $configSource . '.xml'; 72 $configSource = str_replace('/', DIRECTORY_SEPARATOR, $configSource); 73 $cacheSource = $this->cachePath . $configSource . '.cache'; 74 $configSource = $this->configPath . $configSource . '.xml'; 75 if (file_exists($cacheSource) && filemtime($cacheSource) >= filemtime($configSource)) { 76 $cachedPage = unserialize(file_get_contents($cacheSource)); 77 foreach ($cachedPage['classes'] as $class) { 78 stubClassLoader::load($class); 79 } 80 81 $page = unserialize($cachedPage['data']); 82 return $page; 83 } 84 85 $page = $this->getPageFromXJConf($configSource); 86 $cachedPage = array('classes' => array($page->getClassName()), 87 'data' => serialize($page) 88 ); 89 foreach ($page->getElements() as $pageElement) { 90 $cachedPage['classes'][] = $pageElement->getClassName(); 91 foreach ($pageElement->getRequiredClassNames() as $requiredClassName) { 92 $cachedPage['classes'][] = $requiredClassName; 93 } 94 } 95 96 if (file_exists(dirname($cacheSource)) == false) { 97 mkdir(dirname($cacheSource), 0700, true); 98 } 99 100 file_put_contents($cacheSource, serialize($cachedPage)); 101 return $page; 102 } 103 104 /** 105 * returns the configured stubPage instance 106 * 107 * @param string $configSource source of the page configuration to use 108 * @return stubPage 109 * @throws stubPageConfigurationException 110 */ 111 protected function getPageFromXJConf($configSource) 112 { 113 if (null == self::$xjconf) { 114 stubClassLoader::load('net.stubbles.util.stubFactory', 115 'net.stubbles.util.xjconf.xjconfReal' 116 ); 117 self::$xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 118 self::$xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/websites.xml')); 119 } 120 62 121 try { 63 122 self::$xjconf->parse($configSource); 123 return self::$xjconf->getConfigValue('page'); 64 124 } catch (stubXJConfException $xjce) { 65 125 throw new stubPageConfigurationException('Can not read page configuration from ' . $configSource, $xjce); 66 126 } 67 68 return self::$xjconf->getConfigValue('page');69 127 } 70 128 } trunk/src/main/php/net/stubbles/websites/xml/stubXMLPageElementDecorator.php
r565 r589 15 15 * @subpackage websites 16 16 */ 17 abstract class stubXMLPageElementDecorator implements stubXMLPageElement17 abstract class stubXMLPageElementDecorator extends stubBaseObject implements stubXMLPageElement 18 18 { 19 19 /** … … 49 49 public function getName() { 50 50 return $this->element->getName(); 51 } 52 53 /** 54 * returns a list of required class names 55 * 56 * @return array<string> 57 */ 58 public function getRequiredClassNames() 59 { 60 return array($this->element->getClassName()); 51 61 } 52 62 trunk/src/test/runIntegration.php
r563 r589 36 36 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/ProcessorTestCase.php'); 37 37 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/RegistryTestCase.php'); 38 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/stubPageXJConfFactoryTestCase.php'); 38 39 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/stubRequestValueErrorXJConfFactoryTestCase.php'); 39 40 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/VariantManagerTestCase.php');
