Changeset 557
- Timestamp:
- 04/18/07 18:10:54 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php (added)
- trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php (modified) (6 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/stubPageFactory.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/processors/stubAbstractProcessorResolverTestCase.php (added)
- trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/processors/stubSimpleProcessorResolverTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php
r369 r557 7 7 * @subpackage websites_processors 8 8 */ 9 stubClassLoader::load('net.stubbles.websites.processors.stub ProcessorResolver',9 stubClassLoader::load('net.stubbles.websites.processors.stubAbstractProcessorResolver', 10 10 'net.stubbles.util.validators.stubPreSelectValidator' 11 11 ); … … 17 17 * @subpackage websites_processors 18 18 */ 19 class stubDefaultProcessorResolver extends stub BaseObject implements stubProcessorResolver19 class stubDefaultProcessorResolver extends stubAbstractProcessorResolver 20 20 { 21 21 /** … … 31 31 */ 32 32 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 40 34 /** 41 35 * adds a processor to the list of available processors … … 48 42 $this->processors[$paramValue] = $fqClassName; 49 43 } 50 44 51 45 /** 52 46 * sets the name of the default processor … … 58 52 $this->defaultProcessor = $defaultProcessor; 59 53 } 60 54 61 55 /** 62 * sets the page factory to use to read the page configuration56 * does the real resolving work 63 57 * 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 88 62 * @throws stubProcessorException 89 63 */ 90 p ublic function resolve(stubRequest $request, stubSession $session, stubResponse $response)64 protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) 91 65 { 92 if (count($this->processors) == 0) {93 throw new stubProcessorException('Configuration error: no processors have been added to the resolver.');94 }95 96 66 if (isset($this->processors[$this->defaultProcessor]) == false) { 97 67 throw new stubProcessorException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); … … 107 77 } 108 78 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 116 79 $session->putValue('net.stubbles.websites.lastProcessor', $paramValue); 117 return $ processor;80 return $this->processors[$paramValue]; 118 81 } 119 82 } trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php
r368 r557 8 8 */ 9 9 stubClassLoader::load('net.stubbles.ipo.request.stubRequest', 10 'net.stubbles.ipo.response.stubResponse', 10 11 'net.stubbles.ipo.session.stubSession', 11 12 'net.stubbles.websites.processors.stubProcessor', … … 20 21 * @subpackage websites_processors 21 22 */ 22 interface stubProcessorResolver 23 interface stubProcessorResolver extends stubSerializable 23 24 { 24 25 /** … … 28 29 */ 29 30 public function setPageFactory(stubPageFactory $pageFactory); 30 31 31 32 /** 32 33 * returns the page factory delivered within the constructor … … 35 36 */ 36 37 public function getPageFactory(); 37 38 38 39 /** 39 40 * resolves the request and creates the appropriate processor trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php
r368 r557 7 7 * @subpackage websites_processors 8 8 */ 9 stubClassLoader::load('net.stubbles.websites.processors.stub ProcessorResolver');9 stubClassLoader::load('net.stubbles.websites.processors.stubAbstractProcessorResolver'); 10 10 /** 11 11 * A very simple implementation for the processor resolver which returns always the same processor. 12 12 * 13 * @static14 13 * @package stubbles 15 14 * @subpackage websites_processors 16 15 */ 17 class stubSimpleProcessorResolver extends stub BaseObject implements stubProcessorResolver16 class stubSimpleProcessorResolver extends stubAbstractProcessorResolver 18 17 { 19 18 /** … … 23 22 */ 24 23 protected $processor = null; 25 /**26 * the page factory to use to read the page configuration27 *28 * @var stubPageFactory29 */30 protected $pageFactory = null;31 24 32 25 /** … … 39 32 $this->processor = $fqClassName; 40 33 } 41 42 /**43 * sets the page factory to use to read the page configuration44 *45 * @param stubPageFactory $pageFactory46 */47 public function setPageFactory(stubPageFactory $pageFactory)48 {49 $this->pageFactory = $pageFactory;50 }51 52 /**53 * returns the page factory delivered within the constructor54 *55 * @return stubPageFactory56 */57 public function getPageFactory()58 {59 return $this->pageFactory;60 }61 34 62 35 /** 63 * resolves the request and creates the appropriate processor36 * does the real resolving work 64 37 * 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 70 42 */ 71 p ublic function resolve(stubRequest $request, stubSession $session, stubResponse $response)43 protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) 72 44 { 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; 85 46 } 86 47 } trunk/src/main/php/net/stubbles/websites/stubPageFactory.php
r386 r557 18 18 * @subpackage websites 19 19 */ 20 interface stubPageFactory 20 interface stubPageFactory extends stubObject 21 21 { 22 22 /** trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r542 r557 30 30 31 31 // processors tests 32 $this->addTestFile($dir . '/processors/stubAbstractProcessorResolverTestCase.php'); 32 33 $this->addTestFile($dir . '/processors/stubDefaultProcessorResolverTestCase.php'); 33 34 $this->addTestFile($dir . '/processors/stubSimpleProcessorResolverTestCase.php'); trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php
r368 r557 75 75 $this->defaultProcessorResolver->setDefaultProcessor('foo'); 76 76 } 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 87 78 /** 88 79 * 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 68 68 69 69 /** 70 * assure that the page factory stays the same71 */72 public function testGetPageFactory()73 {74 $pageFactory = $this->simpleProcessorResolver->getPageFactory();75 $this->assertReference($pageFactory, $this->mockPageFactory);76 }77 78 /**79 70 * assure that the default processor is returned and it has all required classes 80 71 */
