Changeset 1445
- Timestamp:
- 03/20/08 17:51:12 (2 months ago)
- Files:
-
- trunk/config/xml/processors.xml (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php (modified) (6 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php (modified) (6 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubProcessorException.php (deleted)
- trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/rasmus/stubPageRasmusFactory.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php (modified) (1 diff)
- trunk/src/main/resources/xjconf/processors.xml (modified) (1 diff)
- trunk/src/test/php/net/stubbles/integration/ProcessorTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/processors/stubAbstractProcessorResolverTestCase.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/xml/processors.xml
r1219 r1445 4 4 xmlns="http://stubbles.net/websites"> 5 5 <defaultResolver default="xml"> 6 <pageFactory type="net::stubbles::websites::stubPageXJConfFactory" /> 7 <processor name="xml" type="net::stubbles::websites::xml::stubXMLProcessor" interceptorDescriptor="interceptors" /> 8 <processor name="page" type="net::stubbles::websites::memphis::stubMemphisProcessor" interceptorDescriptor="interceptors" /> 9 <processor name="jsonrpc" type="net::stubbles::service::jsonrpc::stubJsonRpcProcessor" interceptorDescriptor="interceptors" /> 6 <processor name="xml" type="net::stubbles::websites::xml::stubXMLProcessor" interceptorDescriptor="interceptors" pageFactoryClass="net::stubbles::websites::stubPageXJConfFactory"/> 7 <processor name="page" type="net::stubbles::websites::memphis::stubMemphisProcessor" pageFactoryClass="net::stubbles::websites::stubPageXJConfFactory"/> 8 <processor name="jsonrpc" type="net::stubbles::service::jsonrpc::stubJsonRpcProcessor" interceptorDescriptor="interceptors"/> 10 9 </defaultResolver> 11 10 </xj:configuration> trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php
r1442 r1445 7 7 * @subpackage websites_processors 8 8 */ 9 stubClassLoader::load('net::stubbles::websites::processors::stubPageBasedProcessor', 9 stubClassLoader::load('net::stubbles::lang::exceptions::stubConfigurationException', 10 'net::stubbles::lang::exceptions::stubRuntimeException', 11 'net::stubbles::websites::stubPageFactory', 12 'net::stubbles::websites::processors::stubPageBasedProcessor', 10 13 'net::stubbles::websites::processors::stubProcessorResolver' 11 14 ); … … 19 22 { 20 23 /** 21 * the page factory to use to read the page configuration22 *23 * @var stubPageFactory24 */25 protected $pageFactory = null;26 27 /**28 * sets the page factory to use to read the page configuration29 *30 * @param stubPageFactory $pageFactory31 */32 public function setPageFactory(stubPageFactory $pageFactory)33 {34 $this->pageFactory = $pageFactory;35 }36 37 /**38 * returns the page factory delivered within the constructor39 *40 * @return stubPageFactory41 */42 public function getPageFactory()43 {44 return $this->pageFactory;45 }46 47 /**48 24 * resolves the request and creates the appropriate processor 49 25 * … … 52 28 * @param stubResponse $response the current response 53 29 * @return stubProcessor 54 * @throws stubProcessorException 30 * @throws stubConfigurationException 31 * @throws stubRuntimeException 55 32 */ 56 33 public function resolve(stubRequest $request, stubSession $session, stubResponse $response) … … 58 35 $processorClassName = $this->doResolve($request, $session, $response); 59 36 if (null == $processorClassName) { 60 throw new stub ProcessorException('Configuration error: no processor specified.');37 throw new stubConfigurationException('Configuration error: no processor specified.'); 61 38 } 62 39 … … 64 41 $className = stubClassLoader::getNonQualifiedClassName($processorClassName); 65 42 $processor = new $className($request, $session, $response); 66 if (($processor instanceof stubProcessor) == false) {67 throw new stub ProcessorException($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')); 68 45 } 69 46 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); 76 49 return $processor; 77 50 } … … 84 57 * @param stubResponse $response the current response 85 58 * @return string full qualified classname of the processor to create 86 * @throws stubProcessorException87 59 */ 88 60 protected abstract function doResolve(stubRequest $request, stubSession $session, stubResponse $response); 89 61 90 62 /** 91 * configures the processor with the interceptor descriptor63 * configures the processor 92 64 * 93 65 * @param stubProcessor $processor 94 66 */ 95 protected abstract function configure InterceptorDescriptor(stubProcessor $processor);67 protected abstract function configure(stubProcessor $processor); 96 68 97 69 /** 98 * template method to hook into __sleep()70 * returns the page factory class for the processor 99 71 * 100 * @return array<string> list of property names that should not be serialized 72 * @param stubProcessor $processor 73 * @return string 101 74 */ 102 protected function __doSleep() 103 { 104 $this->_serializedProperties['pageFactory'] = $this->pageFactory->getClassName(); 105 return array('pageFactory'); 106 } 75 protected abstract function getPageFactoryClass(stubProcessor $processor); 107 76 108 77 /** 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 110 83 */ 111 protected function __doWakeUp()84 protected function handlePageBasedProcessor(stubProcessor $processor) 112 85 { 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; 116 88 } 117 89 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); 120 103 } 121 104 } trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php
r1231 r1445 7 7 * @subpackage websites_processors 8 8 */ 9 stubClassLoader::load('net::stubbles::websites::processors::stubAbstractProcessorResolver', 10 'net::stubbles::util::validators::stubPreSelectValidator' 9 stubClassLoader::load('net::stubbles::lang::exceptions::stubConfigurationException', 10 'net::stubbles::util::validators::stubPreSelectValidator', 11 'net::stubbles::websites::processors::stubAbstractProcessorResolver' 11 12 ); 12 13 /** … … 37 38 */ 38 39 protected $interceptorDescriptors = array(); 40 /** 41 * list of page factory classes 42 * 43 * @var array<string,string> 44 */ 45 protected $pageFactoryClasses = array(); 39 46 40 47 /** … … 43 50 * @param string $paramValue value of the request parameter that identifies this processor 44 51 * @param string $fqClassName full qualified class name of the processor 45 * @param string $interceptorDescriptor the interceptor descriptor 52 * @param string $interceptorDescriptor optional the interceptor descriptor 53 * @param string $pageFactoryClass optional page factory class for the processor 46 54 */ 47 public function addProcessor($paramValue, $fqClassName, $interceptorDescriptor )55 public function addProcessor($paramValue, $fqClassName, $interceptorDescriptor = 'interceptors', $pageFactoryClass = null) 48 56 { 49 57 $this->processors[$paramValue] = $fqClassName; 50 58 $this->interceptorDescriptors[$fqClassName] = $interceptorDescriptor; 59 if (null !== $pageFactoryClass) { 60 $this->pageFactoryClasses[$fqClassName] = $pageFactoryClass; 61 } 51 62 } 52 63 … … 68 79 * @param stubResponse $response the current response 69 80 * @return string full qualified classname of the processor to create 70 * @throws stub ProcessorException81 * @throws stubConfigurationException 71 82 */ 72 83 protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) 73 84 { 74 85 if (isset($this->processors[$this->defaultProcessor]) == false) { 75 throw new stub ProcessorException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.');86 throw new stubConfigurationException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); 76 87 } 77 88 … … 90 101 91 102 /** 92 * configures the processor with the interceptor descriptor103 * configures the processor 93 104 * 94 105 * @param stubProcessor $processor 95 106 */ 96 protected function configure InterceptorDescriptor(stubProcessor $processor)107 protected function configure(stubProcessor $processor) 97 108 { 98 109 if (isset($this->interceptorDescriptors[$processor->getClassName()]) == true && strlen($this->interceptorDescriptors[$processor->getClassName()]) > 0) { … … 100 111 } 101 112 } 113 114 /** 115 * returns the page factory class for the processor 116 * 117 * @param stubProcessor $processor 118 * @return string 119 */ 120 protected function getPageFactoryClass(stubProcessor $processor) 121 { 122 if (isset($this->pageFactoryClasses[$processor->getClassName()]) === true) { 123 return $this->pageFactoryClasses[$processor->getClassName()]; 124 } 125 126 return null; 127 } 102 128 } 103 129 ?> trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php
r1231 r1445 10 10 'net::stubbles::ipo::response::stubResponse', 11 11 'net::stubbles::ipo::session::stubSession', 12 'net::stubbles::websites::processors::stubProcessor', 13 'net::stubbles::websites::processors::stubProcessorException', 14 'net::stubbles::websites::stubPageFactory' 12 'net::stubbles::websites::processors::stubProcessor' 15 13 ); 16 14 /** … … 23 21 { 24 22 /** 25 * sets the page factory to use to read the page configuration26 *27 * @param stubPageFactory $pageFactory28 */29 public function setPageFactory(stubPageFactory $pageFactory);30 31 /**32 * returns the page factory delivered within the constructor33 *34 * @return stubPageFactory35 */36 public function getPageFactory();37 38 /**39 23 * resolves the request and creates the appropriate processor 40 24 * … … 43 27 * @param stubResponse $response the current response 44 28 * @return stubProcessor 45 * @throws stubProcessorException46 29 */ 47 30 public function resolve(stubRequest $request, stubSession $session, stubResponse $response); trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php
r1231 r1445 21 21 * @var string 22 22 */ 23 protected $processor = null; 23 protected $processor = null; 24 /** 25 * page factory class to be used 26 * 27 * @var string 28 */ 29 protected $pageFactoryClass = null; 24 30 25 31 /** … … 31 37 { 32 38 $this->processor = $fqClassName; 39 } 40 41 /** 42 * sets the page factory class to be used 43 * 44 * @param string $pageFactoryClass 45 */ 46 public function setPageFactoryClass($pageFactoryClass) 47 { 48 $this->pageFactoryClass = $pageFactoryClass; 33 49 } 34 50 … … 47 63 48 64 /** 49 * configures the processor with the interceptor descriptor65 * configures the processor 50 66 * 51 67 * @param stubProcessor $processor 52 68 */ 53 protected function configure InterceptorDescriptor(stubProcessor $processor)69 protected function configure(stubProcessor $processor) 54 70 { 55 71 $processor->setInterceptorDescriptor('interceptors'); 56 72 } 73 74 /** 75 * returns the page factory class for the processor 76 * 77 * @param stubProcessor $processor 78 * @return string 79 */ 80 protected function getPageFactoryClass(stubProcessor $processor) 81 { 82 return $this->pageFactoryClass; 83 } 57 84 } 58 85 ?> trunk/src/main/php/net/stubbles/websites/rasmus/stubPageRasmusFactory.php
r1438 r1445 63 63 * returns the configured stubPage instance 64 64 * 65 * @param string $configSource source of the page configuration to use66 * @return stub RasmusPage65 * @param string $pageName name of the page to retrieve 66 * @return stubPage 67 67 */ 68 p ublic function getPage($configSource)68 protected function doGetPage($configSource) 69 69 { 70 70 $page = new stubRasmusPage($this->configPath . $configSource . '.php'); trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php
r1438 r1445 65 65 * returns the configured stubPage instance 66 66 * 67 * @param string $ configSource source of the page configuration to use67 * @param string $pageName name of the page to retrieve 68 68 * @return stubPage 69 69 */ 70 p ublic function getPage($configSource)70 protected function doGetPage($configSource) 71 71 { 72 72 $configSource = str_replace('/', DIRECTORY_SEPARATOR, $this->pagePrefix . $configSource); trunk/src/main/resources/xjconf/processors.xml
r1219 r1445 3 3 <namespace uri="http://stubbles.net/websites"> 4 4 <tag name="defaultResolver" type="net::stubbles::websites::processors::stubDefaultProcessorResolver" key="resolver"> 5 <attribute name="default" type="string" setter="setDefaultProcessor" />5 <attribute name="default" type="string" setter="setDefaultProcessor"/> 6 6 <methodCallTag name="processor" method="addProcessor"> 7 <attribute name="name" type="string" /> 8 <attribute name="type" type="string" /> 9 <attribute name="interceptorDescriptor" type="string" /> 7 <attribute name="name" type="string"/> 8 <attribute name="type" type="string"/> 9 <attribute name="interceptorDescriptor" type="string"/> 10 <attribute name="pageFactoryClass" type="string"/> 10 11 </methodCallTag> 11 12 </tag> 12 13 <tag name="simpleResolver" type="net::stubbles::websites::processors::stubSimpleProcessorResolver" key="resolver"> 13 <attribute name="processor" type="string" />14 <attribute name=" interceptorDescriptor" type="string"/>14 <attribute name="processor" type="string"/> 15 <attribute name="pageFactoryClass" type="string"/> 15 16 </tag> 16 <abstractTag name="pageFactory" abstractType="net::stubbles::websites::stubPageFactory" concreteTypeAttribute="type" />17 17 </namespace> 18 18 </defines> trunk/src/test/php/net/stubbles/integration/ProcessorTestCase.php
r1308 r1445 37 37 $processorResolver = $this->getProcessorResolver(); 38 38 $this->assertType('stubProcessorResolver', $processorResolver); 39 $pageFactory = $processorResolver->getPageFactory();40 $this->assertType('stubPageFactory', $pageFactory);41 39 $processor = $processorResolver->resolve($this->getMock('stubRequest'), $this->getMock('stubSession'), $this->getMock('stubResponse')); 42 40 $this->assertType('stubProcessor', $processor); … … 45 43 $processorResolver = $this->getProcessorResolver(); 46 44 $this->assertType('stubProcessorResolver', $processorResolver); 47 $pageFactory = $processorResolver->getPageFactory();48 $this->assertType('stubPageFactory', $pageFactory);49 45 $processor = $processorResolver->resolve($this->getMock('stubRequest'), $this->getMock('stubSession'), $this->getMock('stubResponse')); 50 46 $this->assertType('stubProcessor', $processor); trunk/src/test/php/net/stubbles/websites/processors/stubAbstractProcessorResolverTestCase.php
r1442 r1445 23 23 protected $abstractProcessorResolver; 24 24 /** 25 * mocked page factory to use26 *27 * @var PHPUnit_Framework_MockObject_MockObject28 */29 protected $mockPageFactory;30 /**31 25 * mocked request to use 32 26 * … … 52 46 public function setUp() 53 47 { 54 $this->abstractProcessorResolver = $this->getMock('stubAbstractProcessorResolver', array('doResolve', 'configureInterceptorDescriptor')); 55 56 $this->mockPageFactory = $this->getMock('stubPageFactory'); 57 $this->abstractProcessorResolver->setPageFactory($this->mockPageFactory); 58 48 $this->abstractProcessorResolver = $this->getMock('stubAbstractProcessorResolver', 49 array('doResolve', 50 'configure', 51 'getPageFactoryClass' 52 ) 53 ); 59 54 $this->mockRequest = $this->getMock('stubRequest'); 60 55 $this->mockSession = $this->getMock('stubSession'); … … 63 58 64 59 /** 65 * assure that the page factory stays the same66 *67 * @test68 */69 public function getPageFactory()70 {71 $pageFactory = $this->abstractProcessorResolver->getPageFactory();72 $this->assertSame($this->mockPageFactory, $pageFactory);73 }74 75 /**76 60 * test that a missing return value of doResolve() triggers an exception 77 61 * 78 62 * @test 79 * @expectedException stub ProcessorException63 * @expectedException stubConfigurationException 80 64 */ 81 65 public function noProcessorThrowsException() … … 92 76 * 93 77 * @test 94 * @expectedException stub ProcessorException78 * @expectedException stubRuntimeException 95 79 */ 96 80 public function falseProcessorThrowsException() … … 123 107 $this->assertSame($this->mockResponse, $response); 124 108 } 125 126 /**127 * test that __sleep() returns a list of properties without the pageFactory128 *129 * @test130 */131 public function sleep()132 {133 $keys = $this->abstractProcessorResolver->__sleep();134 $this->assertFalse(in_array('pageFactory', $keys));135 }136 137 /**138 * test that the resolver is serialized and unserialized correct139 *140 * @test141 */142 public function serialize()143 {144 $class = get_class($this->getMock('stubPageFactory'));145 $this->mockPageFactory->expects($this->once())146 ->method('getClassName')147 ->will($this->returnValue($class));148 $serialized = serialize($this->abstractProcessorResolver);149 $unserialized = unserialize($serialized);150 $this->assertType($class, $unserialized->getPageFactory());151 }152 109 } 153 110 ?> trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php
r1252 r1445 130 130 * 131 131 * @test 132 * @expectedException stub ProcessorException132 * @expectedException stubConfigurationException 133 133 */ 134 134 public function noProcessors() … … 141 141 * 142 142 * @test 143 * @expectedException stub ProcessorException143 * @expectedException stubConfigurationException 144 144 */ 145 145 public function wrongDefaultProcessors()
