Changeset 807

Show
Ignore:
Timestamp:
08/13/07 18:16:16 (1 year ago)
Author:
mikey
Message:

refactored net.stubbles.websites.memphis.stubMemphisConfig, added integration test

Files:

Legend:

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

    r803 r807  
    3636    </frames> 
    3737    <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&amp;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> 
    4040    </metaTags> 
    4141  </config> 
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisConfig.php

    r803 r807  
    1414 * @subpackage  websites_memphis 
    1515 */ 
    16 class stubMemphisConfig extends stubBaseObject 
     16class stubMemphisConfig extends stubXJConfAbstractInitializer 
    1717{ 
    1818    /** 
    1919     * holds the configuration data 
    2020     * 
    21      * @var  array 
     21     * @var  array<string,mixed> 
    2222     */ 
    2323    protected $config; 
     
    3232    public function __construct($cachePath = null, $configPath = null) 
    3333    { 
    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(); 
    3736        if (isset($this->config['parts']) == false || count($this->config['parts']) == 0) { 
    3837            throw new stubException('No parts configured.'); 
     
    4544 
    4645    /** 
     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    /** 
    47117     * returns the list of parts 
    48118     * 
     
    51121    public function getParts() 
    52122    { 
    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(); 
    54139    } 
    55140 
     
    86171        return array(); 
    87172    } 
    88  
    89     /** 
    90      * returns the configuration 
    91      * 
    92      * @return  array 
    93      * @throws  stubException 
    94      */ 
    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 instance 
    135      * 
    136      * @param   string    $configSource   source of the page configuration to use 
    137      * @return  array 
    138      * @throws  stubException 
    139      */ 
    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     } 
    157173} 
    158174?> 
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php

    r803 r807  
    4646    { 
    4747        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(); 
    5070    } 
    5171 
     
    6686        $content       = array(); 
    6787        $context       = array('part' => null, 
    68                                'tmpl' => $this->template 
     88                               'tmpl' => $this->template, 
     89                               'page' => $page 
    6990                         ); 
    7091         
    7192        $this->template->readTemplatesFromFile($this->config->getFrame($this->getFrameId($page))); 
    7293        $this->setTemplateVars($page); 
    73         $parts = $this->config->getParts(); 
    74         foreach (array_keys($parts) as $part) { 
     94        foreach ($this->config->getParts() as $part) { 
    7595            $content         = ''; 
    7696            $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); 
    82100            } 
    83101             
  • trunk/src/main/resources/xjconf/websites.xml

    r803 r807  
    1212    <tag name="property" type="string" keyAttribute="name" /> 
    1313     
    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"
    1515      <attribute name="name" type="string" /> 
    1616    </abstractTag> 
    1717     
    1818    <!-- 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"
    2020      <attribute name="parts" type="string" /> 
    2121    </abstractTag> 
    2222     
    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"
    2424      <attribute name="source" type="string" /> 
    2525    </tag> 
    2626     
    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"
    2828      <attribute name="source" type="string" /> 
    2929    </tag> 
    3030     
    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"
    3232      <attribute name="extension" type="string" /> 
    3333    </tag--> 
     
    3939     
    4040    <!-- 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" /> 
    4242 
    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"
    4444      <attribute name="directory" type="string"/> 
    4545      <attribute name="fileName" type="string"/> 
     
    4747     
    4848    <!-- 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"
    5050      <constructor> 
    5151        <child name="xmlElement"/> 
     
    5353    </abstractTag> 
    5454 
    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"
    5656      <attribute name="lifetime" type="int"/> 
    5757    </tag> 
  • trunk/src/test/runIntegration.php

    r742 r807  
    3636        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/InterceptorTestCase.php'); 
    3737        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/LoggerTestCase.php'); 
     38        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/MemphisConfigTestCase.php'); 
    3839        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/ProcessorTestCase.php'); 
    3940        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/RegistryTestCase.php');