| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | stubClassLoader::load('net::stubbles::lang::exceptions::stubConfigurationException', |
|---|
| 10 | 'net::stubbles::util::validators::stubPreSelectValidator', |
|---|
| 11 | 'net::stubbles::websites::processors::stubAbstractProcessorResolver' |
|---|
| 12 | ); |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | class stubDefaultProcessorResolver extends stubAbstractProcessorResolver |
|---|
| 21 | { |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | protected $defaultProcessor = null; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | protected $processors = array(); |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | protected $interceptorDescriptors = array(); |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | protected $pageFactoryClasses = array(); |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | public function addProcessor($paramValue, $fqClassName, $interceptorDescriptor = 'interceptors', $pageFactoryClass = null) |
|---|
| 56 | { |
|---|
| 57 | $this->processors[$paramValue] = $fqClassName; |
|---|
| 58 | $this->interceptorDescriptors[$fqClassName] = $interceptorDescriptor; |
|---|
| 59 | if (null !== $pageFactoryClass) { |
|---|
| 60 | $this->pageFactoryClasses[$fqClassName] = $pageFactoryClass; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | public function setDefaultProcessor($defaultProcessor) |
|---|
| 70 | { |
|---|
| 71 | $this->defaultProcessor = $defaultProcessor; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) |
|---|
| 84 | { |
|---|
| 85 | if (isset($this->processors[$this->defaultProcessor]) == false) { |
|---|
| 86 | throw new stubConfigurationException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | if ($request->hasValue('processor') == false) { |
|---|
| 90 | $paramValue = $this->defaultProcessor; |
|---|
| 91 | } else { |
|---|
| 92 | $paramValue = $request->getValidatedValue(new stubPreSelectValidator(array_keys($this->processors)), 'processor'); |
|---|
| 93 | if (null == $paramValue) { |
|---|
| 94 | $paramValue = $this->defaultProcessor; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | $session->putValue('net::stubbles::websites.lastProcessor', $paramValue); |
|---|
| 99 | return $this->processors[$paramValue]; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | protected function configure(stubProcessor $processor) |
|---|
| 108 | { |
|---|
| 109 | if (isset($this->interceptorDescriptors[$processor->getClassName()]) == true && strlen($this->interceptorDescriptors[$processor->getClassName()]) > 0) { |
|---|
| 110 | $processor->setInterceptorDescriptor($this->interceptorDescriptors[$processor->getClassName()]); |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 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 | } |
|---|
| 128 | } |
|---|
| 129 | ?> |
|---|