Changeset 1445 for trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php
- Timestamp:
- 03/20/08 17:51:12 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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 }
