| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
stubClassLoader::load('net::stubbles::ipo::request::validator::stubPreSelectValidator', |
|---|
| 10 |
'net::stubbles::lang::exceptions::stubConfigurationException', |
|---|
| 11 |
'net::stubbles::websites::processors::stubAbstractProcessorResolver' |
|---|
| 12 |
); |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
class stubDefaultProcessorResolver extends stubAbstractProcessorResolver |
|---|
| 47 |
{ |
|---|
| 48 |
|
|---|
| 49 |
* the default processor to use |
|---|
| 50 |
* |
|---|
| 51 |
* @var string |
|---|
| 52 |
*/ |
|---|
| 53 |
protected $defaultProcessor = null; |
|---|
| 54 |
|
|---|
| 55 |
* list of processors |
|---|
| 56 |
* |
|---|
| 57 |
* @var array<string,string> |
|---|
| 58 |
*/ |
|---|
| 59 |
protected $processors = array(); |
|---|
| 60 |
|
|---|
| 61 |
* list of interceptor descriptors |
|---|
| 62 |
* |
|---|
| 63 |
* @var array<string,string> |
|---|
| 64 |
*/ |
|---|
| 65 |
protected $interceptorDescriptors = array(); |
|---|
| 66 |
|
|---|
| 67 |
* list of page factory classes |
|---|
| 68 |
* |
|---|
| 69 |
* @var array<string,string> |
|---|
| 70 |
*/ |
|---|
| 71 |
protected $pageFactoryClasses = array(); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
* adds a processor to the list of available processors |
|---|
| 75 |
* |
|---|
| 76 |
* @param string $paramValue value of the request parameter that identifies this processor |
|---|
| 77 |
* @param string $fqClassName full qualified class name of the processor |
|---|
| 78 |
* @param string $interceptorDescriptor optional the interceptor descriptor |
|---|
| 79 |
* @param string $pageFactoryClass optional page factory class for the processor |
|---|
| 80 |
*/ |
|---|
| 81 |
public function addProcessor($paramValue, $fqClassName, $interceptorDescriptor = null, $pageFactoryClass = null) |
|---|
| 82 |
{ |
|---|
| 83 |
$this->processors[$paramValue] = $fqClassName; |
|---|
| 84 |
if (null != $interceptorDescriptor) { |
|---|
| 85 |
$this->interceptorDescriptors[$fqClassName] = $interceptorDescriptor; |
|---|
| 86 |
} else { |
|---|
| 87 |
$this->interceptorDescriptors[$fqClassName] = 'interceptors'; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
if (null !== $pageFactoryClass) { |
|---|
| 91 |
$this->pageFactoryClasses[$fqClassName] = $pageFactoryClass; |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
* sets the name of the default processor |
|---|
| 97 |
* |
|---|
| 98 |
* @param string $defaultProcessor value of the request parameter that identifies this processor |
|---|
| 99 |
*/ |
|---|
| 100 |
public function setDefaultProcessor($defaultProcessor) |
|---|
| 101 |
{ |
|---|
| 102 |
$this->defaultProcessor = $defaultProcessor; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
* does the real resolving work |
|---|
| 107 |
* |
|---|
| 108 |
* @param stubRequest $request the current request |
|---|
| 109 |
* @param stubSession $session the current session |
|---|
| 110 |
* @param stubResponse $response the current response |
|---|
| 111 |
* @return string full qualified classname of the processor to create |
|---|
| 112 |
* @throws stubConfigurationException |
|---|
| 113 |
*/ |
|---|
| 114 |
protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) |
|---|
| 115 |
{ |
|---|
| 116 |
$paramValue = null; |
|---|
| 117 |
if ($request->hasValue('processor') === true) { |
|---|
| 118 |
$paramValue = $request->getValidatedValue(new stubPreSelectValidator(array_keys($this->processors)), 'processor'); |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
if (null == $paramValue) { |
|---|
| 122 |
if (null == $this->defaultProcessor || isset($this->processors[$this->defaultProcessor]) === false) { |
|---|
| 123 |
throw new stubConfigurationException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
$paramValue = $this->defaultProcessor; |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
$session->putValue('net.stubbles.websites.lastProcessor', $paramValue); |
|---|
| 130 |
return $this->processors[$paramValue]; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
* configures the processor |
|---|
| 135 |
* |
|---|
| 136 |
* @param stubProcessor $processor |
|---|
| 137 |
*/ |
|---|
| 138 |
protected function configure(stubProcessor $processor) |
|---|
| 139 |
{ |
|---|
| 140 |
$processorClassName = $processor->getClassName(); |
|---|
| 141 |
if (isset($this->interceptorDescriptors[$processorClassName]) === true && strlen($this->interceptorDescriptors[$processorClassName]) > 0) { |
|---|
| 142 |
$processor->setInterceptorDescriptor($this->interceptorDescriptors[$processorClassName]); |
|---|
| 143 |
} |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
* returns the page factory class for the processor |
|---|
| 148 |
* |
|---|
| 149 |
* @param stubProcessor $processor |
|---|
| 150 |
* @return string |
|---|
| 151 |
*/ |
|---|
| 152 |
protected function getPageFactoryClass(stubProcessor $processor) |
|---|
| 153 |
{ |
|---|
| 154 |
$processorClassName = $processor->getClassName(); |
|---|
| 155 |
if (isset($this->pageFactoryClasses[$processorClassName]) === true) { |
|---|
| 156 |
return $this->pageFactoryClasses[$processorClassName]; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
return null; |
|---|
| 160 |
} |
|---|
| 161 |
} |
|---|
| 162 |
?> |
|---|