Show
Ignore:
Timestamp:
03/20/08 17:51:12 (2 years ago)
Author:
mikey
Message:

refactoring #137, part 7: page factories are now attributes of the processors, and not of the resolvers

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php

    r1442 r1445  
    77 * @subpackage  websites_processors 
    88 */ 
    9 stubClassLoader::load('net::stubbles::websites::processors::stubPageBasedProcessor', 
     9stubClassLoader::load('net::stubbles::lang::exceptions::stubConfigurationException', 
     10                      'net::stubbles::lang::exceptions::stubRuntimeException', 
     11                      'net::stubbles::websites::stubPageFactory', 
     12                      'net::stubbles::websites::processors::stubPageBasedProcessor', 
    1013                      'net::stubbles::websites::processors::stubProcessorResolver' 
    1114); 
     
    1922{ 
    2023    /** 
    21      * the page factory to use to read the page configuration 
    22      * 
    23      * @var  stubPageFactory 
    24      */ 
    25     protected $pageFactory = null; 
    26  
    27     /** 
    28      * sets the page factory to use to read the page configuration 
    29      * 
    30      * @param  stubPageFactory  $pageFactory 
    31      */ 
    32     public function setPageFactory(stubPageFactory $pageFactory) 
    33     { 
    34         $this->pageFactory = $pageFactory; 
    35     } 
    36  
    37     /** 
    38      * returns the page factory delivered within the constructor 
    39      * 
    40      * @return  stubPageFactory 
    41      */ 
    42     public function getPageFactory() 
    43     { 
    44         return $this->pageFactory; 
    45     } 
    46  
    47     /** 
    4824     * resolves the request and creates the appropriate processor 
    4925     * 
     
    5228     * @param   stubResponse   $response  the current response 
    5329     * @return  stubProcessor 
    54      * @throws  stubProcessorException 
     30     * @throws  stubConfigurationException 
     31     * @throws  stubRuntimeException 
    5532     */ 
    5633    public function resolve(stubRequest $request, stubSession $session, stubResponse $response) 
     
    5835        $processorClassName = $this->doResolve($request, $session, $response); 
    5936        if (null == $processorClassName) { 
    60             throw new stubProcessorException('Configuration error: no processor specified.'); 
     37            throw new stubConfigurationException('Configuration error: no processor specified.'); 
    6138        } 
    6239         
     
    6441        $className = stubClassLoader::getNonQualifiedClassName($processorClassName); 
    6542        $processor = new $className($request, $session, $response); 
    66         if (($processor instanceof stubProcessor) == false) { 
    67             throw new stubProcessorException($processorClassName . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); 
     43        if (($processor instanceof stubProcessor) === false) { 
     44            throw new stubRuntimeException($processorClassName . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); 
    6845        } 
    6946         
    70         $this->configureInterceptorDescriptor($processor); 
    71          
    72         if ($processor instanceof stubPageBasedProcessor) { 
    73             $processor->selectPage($this->pageFactory); 
    74         } 
    75          
     47        $this->configure($processor); 
     48        $this->handlePageBasedProcessor($processor); 
    7649        return $processor; 
    7750    } 
     
    8457     * @param   stubResponse  $response  the current response 
    8558     * @return  string        full qualified classname of the processor to create 
    86      * @throws  stubProcessorException 
    8759     */ 
    8860    protected abstract function doResolve(stubRequest $request, stubSession $session, stubResponse $response); 
    8961 
    9062    /** 
    91      * configures the processor with the interceptor descriptor 
     63     * configures the processor 
    9264     * 
    9365     * @param  stubProcessor  $processor 
    9466     */ 
    95     protected abstract function configureInterceptorDescriptor(stubProcessor $processor); 
     67    protected abstract function configure(stubProcessor $processor); 
    9668 
    9769    /** 
    98      * template method to hook into __sleep() 
     70     * returns the page factory class for the processor 
    9971     * 
    100      * @return  array<string>  list of property names that should not be serialized 
     72     * @param   stubProcessor  $processor 
     73     * @return  string 
    10174     */ 
    102     protected function __doSleep() 
    103     { 
    104         $this->_serializedProperties['pageFactory'] = $this->pageFactory->getClassName(); 
    105         return array('pageFactory'); 
    106     } 
     75    protected abstract function getPageFactoryClass(stubProcessor $processor); 
    10776 
    10877    /** 
    109      * template method to hook into __wakeup() 
     78     * helper method to handle page based processors 
     79     * 
     80     * @param   stubProcessor  $processor 
     81     * @throws  stubConfigurationException 
     82     * @throws  stubRuntimeException 
    11083     */ 
    111     protected function __doWakeUp() 
     84    protected function handlePageBasedProcessor(stubProcessor $processor) 
    11285    { 
    113         $nqClassName = stubClassLoader::getNonQualifiedClassName($this->_serializedProperties['pageFactory']); 
    114         if (class_exists($nqClassName, false) == false) { 
    115             stubClassLoader::load($this->_serializedProperties['pageFactory']); 
     86        if (($processor instanceof stubPageBasedProcessor) === false) { 
     87            return; 
    11688        } 
    11789         
    118         $this->pageFactory = new $nqClassName(); 
    119         unset($this->_serializedProperties['pageFactory']); 
     90        $pageFactoryClass = $this->getPageFactoryClass($processor); 
     91        if (null == $pageFactoryClass) { 
     92            throw new stubConfigurationException('Configuration error: processor ' . $processor->getClassName() . ' requires page factory, but no page factory class configured.'); 
     93        } 
     94         
     95        stubClassLoader::load($pageFactoryClass); 
     96        $nqClassName = stubClassLoader::getNonQualifiedClassName($pageFactoryClass); 
     97        $pageFactory = new $nqClassName(); 
     98        if (($pageFactory instanceof stubPageFactory) === false) { 
     99            throw new stubRuntimeException($processor->getClassName() . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubPageFactory')); 
     100        } 
     101         
     102        $processor->selectPage($pageFactory); 
    120103    } 
    121104}