Changeset 557

Show
Ignore:
Timestamp:
04/18/07 18:10:54 (1 year ago)
Author:
mikey
Message:

created common abstract base class for net.stubbles.websites.processors.stubProcessorResolver
(needs still to be finished)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php

    r369 r557  
    77 * @subpackage  websites_processors 
    88 */ 
    9 stubClassLoader::load('net.stubbles.websites.processors.stubProcessorResolver', 
     9stubClassLoader::load('net.stubbles.websites.processors.stubAbstractProcessorResolver', 
    1010                      'net.stubbles.util.validators.stubPreSelectValidator' 
    1111); 
     
    1717 * @subpackage  websites_processors 
    1818 */ 
    19 class stubDefaultProcessorResolver extends stubBaseObject implements stubProcessorResolver 
     19class stubDefaultProcessorResolver extends stubAbstractProcessorResolver 
    2020{ 
    2121    /** 
     
    3131     */ 
    3232    protected $processors       = array(); 
    33     /** 
    34      * the page factory to use to read the page configuration 
    35      * 
    36      * @var  stubPageFactory 
    37      */ 
    38     protected $pageFactory      = null; 
    39      
     33 
    4034    /** 
    4135     * adds a processor to the list of available processors 
     
    4842        $this->processors[$paramValue] = $fqClassName; 
    4943    } 
    50      
     44 
    5145    /** 
    5246     * sets the name of the default processor 
     
    5852        $this->defaultProcessor = $defaultProcessor; 
    5953    } 
    60      
     54 
    6155    /** 
    62      * sets the page factory to use to read the page configuration 
     56     * does the real resolving work 
    6357     * 
    64      * @param  stubPageFactory  $pageFactory 
    65      */ 
    66     public function setPageFactory(stubPageFactory $pageFactory) 
    67     { 
    68         $this->pageFactory = $pageFactory; 
    69     } 
    70      
    71     /** 
    72      * returns the page factory delivered within the constructor 
    73      * 
    74      * @return  stubPageFactory 
    75      */ 
    76     public function getPageFactory() 
    77     { 
    78         return $this->pageFactory; 
    79     } 
    80      
    81     /** 
    82      * resolves the request and creates the appropriate processor 
    83      * 
    84      * @param   stubRequest    $request   the current request 
    85      * @param   stubSession    $session   the current session 
    86      * @param   stubResponse   $response  the current response 
    87      * @return  stubProcessor 
     58     * @param   stubRequest   $request   the current request 
     59     * @param   stubSession   $session   the current session 
     60     * @param   stubResponse  $response  the current response 
     61     * @return  string        full qualified classname of the processor to create 
    8862     * @throws  stubProcessorException 
    8963     */ 
    90     public function resolve(stubRequest $request, stubSession $session, stubResponse $response) 
     64    protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) 
    9165    { 
    92         if (count($this->processors) == 0) { 
    93             throw new stubProcessorException('Configuration error: no processors have been added to the resolver.'); 
    94         } 
    95          
    9666        if (isset($this->processors[$this->defaultProcessor]) == false) { 
    9767            throw new stubProcessorException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); 
     
    10777        } 
    10878         
    109         stubClassLoader::load($this->processors[$paramValue]); 
    110         $className = stubClassLoader::getNonQualifiedClassName($this->processors[$paramValue]); 
    111         $processor = new $className($request, $session, $response, $this->pageFactory); 
    112         if (($processor instanceof stubProcessor) == false) { 
    113             throw new stubProcessorException($this->processors[$paramValue] . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); 
    114         } 
    115          
    11679        $session->putValue('net.stubbles.websites.lastProcessor', $paramValue); 
    117         return $processor
     80        return $this->processors[$paramValue]
    11881    } 
    11982} 
  • trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php

    r368 r557  
    88 */ 
    99stubClassLoader::load('net.stubbles.ipo.request.stubRequest', 
     10                      'net.stubbles.ipo.response.stubResponse', 
    1011                      'net.stubbles.ipo.session.stubSession', 
    1112                      'net.stubbles.websites.processors.stubProcessor', 
     
    2021 * @subpackage  websites_processors 
    2122 */ 
    22 interface stubProcessorResolver 
     23interface stubProcessorResolver extends stubSerializable 
    2324{ 
    2425    /** 
     
    2829     */ 
    2930    public function setPageFactory(stubPageFactory $pageFactory); 
    30      
     31 
    3132    /** 
    3233     * returns the page factory delivered within the constructor 
     
    3536     */ 
    3637    public function getPageFactory(); 
    37      
     38 
    3839    /** 
    3940     * resolves the request and creates the appropriate processor 
  • trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php

    r368 r557  
    77 * @subpackage  websites_processors 
    88 */ 
    9 stubClassLoader::load('net.stubbles.websites.processors.stubProcessorResolver'); 
     9stubClassLoader::load('net.stubbles.websites.processors.stubAbstractProcessorResolver'); 
    1010/** 
    1111 * A very simple implementation for the processor resolver which returns always the same processor. 
    1212 *  
    13  * @static 
    1413 * @package     stubbles 
    1514 * @subpackage  websites_processors 
    1615 */ 
    17 class stubSimpleProcessorResolver extends stubBaseObject implements stubProcessorResolver 
     16class stubSimpleProcessorResolver extends stubAbstractProcessorResolver 
    1817{ 
    1918    /** 
     
    2322     */ 
    2423    protected $processor   = null; 
    25     /** 
    26      * the page factory to use to read the page configuration 
    27      * 
    28      * @var  stubPageFactory 
    29      */ 
    30     protected $pageFactory = null; 
    3124 
    3225    /** 
     
    3932        $this->processor = $fqClassName; 
    4033    } 
    41      
    42     /** 
    43      * sets the page factory to use to read the page configuration 
    44      * 
    45      * @param  stubPageFactory  $pageFactory 
    46      */ 
    47     public function setPageFactory(stubPageFactory $pageFactory) 
    48     { 
    49         $this->pageFactory = $pageFactory; 
    50     } 
    51      
    52     /** 
    53      * returns the page factory delivered within the constructor 
    54      * 
    55      * @return  stubPageFactory 
    56      */ 
    57     public function getPageFactory() 
    58     { 
    59         return $this->pageFactory; 
    60     } 
    6134 
    6235    /** 
    63      * resolves the request and creates the appropriate processor 
     36     * does the real resolving work 
    6437     * 
    65      * @param   stubRequest    $request   the current request 
    66      * @param   stubSession    $session   the current session 
    67      * @param   stubResponse   $response  the current response 
    68      * @return  stubProcessor 
    69      * @throws  stubProcessorException 
     38     * @param   stubRequest   $request   the current request 
     39     * @param   stubSession   $session   the current session 
     40     * @param   stubResponse  $response  the current response 
     41     * @return  string        full qualified classname of the processor to create 
    7042     */ 
    71     public function resolve(stubRequest $request, stubSession $session, stubResponse $response) 
     43    protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) 
    7244    { 
    73         if (null == $this->processor) { 
    74             throw new stubProcessorException('Configuration error: no processor specified.'); 
    75         } 
    76          
    77         stubClassLoader::load($this->processor); 
    78         $className = stubClassLoader::getNonQualifiedClassName($this->processor); 
    79         $processor = new $className($request, $session, $response, $this->pageFactory); 
    80         if (($processor instanceof stubProcessor) == false) { 
    81             throw new stubProcessorException($this->processor . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); 
    82         } 
    83          
    84         return $processor; 
     45        return $this->processor; 
    8546    } 
    8647} 
  • trunk/src/main/php/net/stubbles/websites/stubPageFactory.php

    r386 r557  
    1818 * @subpackage  websites 
    1919 */ 
    20 interface stubPageFactory 
     20interface stubPageFactory extends stubObject 
    2121{ 
    2222    /** 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r542 r557  
    3030 
    3131        // processors tests 
     32        $this->addTestFile($dir . '/processors/stubAbstractProcessorResolverTestCase.php'); 
    3233        $this->addTestFile($dir . '/processors/stubDefaultProcessorResolverTestCase.php'); 
    3334        $this->addTestFile($dir . '/processors/stubSimpleProcessorResolverTestCase.php'); 
  • trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php

    r368 r557  
    7575        $this->defaultProcessorResolver->setDefaultProcessor('foo'); 
    7676    } 
    77      
    78     /** 
    79      * assure that the page factory stays the same 
    80      */ 
    81     public function testGetPageFactory() 
    82     { 
    83         $pageFactory = $this->defaultProcessorResolver->getPageFactory(); 
    84         $this->assertReference($pageFactory, $this->mockPageFactory); 
    85     } 
    86      
     77 
    8778    /** 
    8879     * assure that the default processor is returned and it has all required classes 
  • trunk/src/test/php/net/stubbles/websites/processors/stubSimpleProcessorResolverTestCase.php

    r544 r557  
    6868 
    6969    /** 
    70      * assure that the page factory stays the same 
    71      */ 
    72     public function testGetPageFactory() 
    73     { 
    74         $pageFactory = $this->simpleProcessorResolver->getPageFactory(); 
    75         $this->assertReference($pageFactory, $this->mockPageFactory); 
    76     } 
    77  
    78     /** 
    7970     * assure that the default processor is returned and it has all required classes 
    8071     */