| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
stubClassLoader::load('net::stubbles::ipo::request::stubRequest', |
|---|
| 10 |
'net::stubbles::ipo::response::stubBaseResponse', |
|---|
| 11 |
'net::stubbles::ipo::session::stubSession', |
|---|
| 12 |
'net::stubbles::lang::stubRegistry', |
|---|
| 13 |
'net::stubbles::websites::stubWebsiteInitializer', |
|---|
| 14 |
'net::stubbles::websites::cache::stubWebsiteCacheFactory' |
|---|
| 15 |
); |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
class stubFrontController extends stubBaseObject |
|---|
| 23 |
{ |
|---|
| 24 |
|
|---|
| 25 |
* initializer |
|---|
| 26 |
* |
|---|
| 27 |
* @var stubWebsiteInitializer |
|---|
| 28 |
*/ |
|---|
| 29 |
protected $websiteInitializer; |
|---|
| 30 |
|
|---|
| 31 |
* contains request data |
|---|
| 32 |
* |
|---|
| 33 |
* @var stubRequest |
|---|
| 34 |
*/ |
|---|
| 35 |
protected $request; |
|---|
| 36 |
|
|---|
| 37 |
* session container |
|---|
| 38 |
* |
|---|
| 39 |
* @var stubSession |
|---|
| 40 |
*/ |
|---|
| 41 |
protected $session; |
|---|
| 42 |
|
|---|
| 43 |
* response container |
|---|
| 44 |
* |
|---|
| 45 |
* @var stubResponse |
|---|
| 46 |
*/ |
|---|
| 47 |
protected $response; |
|---|
| 48 |
|
|---|
| 49 |
* factory for the website cache |
|---|
| 50 |
* |
|---|
| 51 |
* @var stubWebsiteCacheFactory |
|---|
| 52 |
*/ |
|---|
| 53 |
protected $websiteCacheFactory; |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
* constructor |
|---|
| 57 |
* |
|---|
| 58 |
* @param stubWebsiteInitializer $websiteInitializer initializer to init basic stuff |
|---|
| 59 |
*/ |
|---|
| 60 |
public function __construct(stubWebsiteInitializer $websiteInitializer) |
|---|
| 61 |
{ |
|---|
| 62 |
$websiteInitializer->init(); |
|---|
| 63 |
$websiteInitializer->getRegistryInitializer()->init(); |
|---|
| 64 |
if ($websiteInitializer->hasGeneralInitializer() === true) { |
|---|
| 65 |
$websiteInitializer->getGeneralInitializer()->init(); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
$this->websiteInitializer = $websiteInitializer; |
|---|
| 69 |
$this->createInstances(); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
* creates the required instances |
|---|
| 74 |
* |
|---|
| 75 |
* @throws stubRuntimeException |
|---|
| 76 |
*/ |
|---|
| 77 |
protected function createInstances() |
|---|
| 78 |
{ |
|---|
| 79 |
$fqClassName = stubRegistry::getConfig(stubRequest::CLASS_REGISTRY_KEY, 'net::stubbles::ipo::request::stubWebRequest'); |
|---|
| 80 |
$className = stubClassLoader::getNonQualifiedClassName($fqClassName); |
|---|
| 81 |
if (class_exists($className, false) === false) { |
|---|
| 82 |
stubClassLoader::load($fqClassName); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
$this->request = new $className(); |
|---|
| 86 |
if (($this->request instanceof stubRequest) === false) { |
|---|
| 87 |
throw new stubRuntimeException('Configured request class is not an instance of net::stubbles::ipo::request::stubRequest.'); |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
$this->response = new stubBaseResponse(); |
|---|
| 91 |
$fqClassName = stubRegistry::getConfig(stubSession::CLASS_REGISTRY_KEY, 'net::stubbles::ipo::session::stubPHPSession'); |
|---|
| 92 |
$className = stubClassLoader::getNonQualifiedClassName($fqClassName); |
|---|
| 93 |
if (class_exists($className, false) === false) { |
|---|
| 94 |
stubClassLoader::load($fqClassName); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
$this->session = new $className($this->request, $this->response, stubRegistry::getConfig(stubSession::NAME_REGISTRY_KEY, stubSession::DEFAULT_SESSION_NAME)); |
|---|
| 98 |
if (($this->session instanceof stubSession) === false) { |
|---|
| 99 |
throw new stubRuntimeException('Configured session class is not an instance of net::stubbles::ipo::session::stubSession.'); |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
* sets the website cache factory to be used |
|---|
| 105 |
* |
|---|
| 106 |
* @param stubWebsiteCacheFactory $websiteCacheFactory |
|---|
| 107 |
*/ |
|---|
| 108 |
public function setWebsiteCacheFactory(stubWebsiteCacheFactory $websiteCacheFactory) |
|---|
| 109 |
{ |
|---|
| 110 |
$this->websiteCacheFactory = $websiteCacheFactory; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
* does the whole processing |
|---|
| 115 |
*/ |
|---|
| 116 |
public function process() |
|---|
| 117 |
{ |
|---|
| 118 |
if ($this->request->isCancelled() === true) { |
|---|
| 119 |
$this->response->send(); |
|---|
| 120 |
return; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
$processorResolverFactory = $this->websiteInitializer->getProcessorResolverFactory(); |
|---|
| 124 |
$processorResolverFactory->init(); |
|---|
| 125 |
$processor = $processorResolverFactory->getResolver()->resolve($this->request, $this->session, $this->response); |
|---|
| 126 |
if ($processor->forceSSL() === true && $processor->isSSL() === false) { |
|---|
| 127 |
$this->response->addHeader('Location', 'https://' . $this->request->getURI()); |
|---|
| 128 |
$this->request->cancel(); |
|---|
| 129 |
$this->response->send(); |
|---|
| 130 |
return; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
$interceptorInitializer = $this->websiteInitializer->getInterceptorInitializer(); |
|---|
| 134 |
$interceptorInitializer->setDescriptor($processor->getInterceptorDescriptor()); |
|---|
| 135 |
$interceptorInitializer->init(); |
|---|
| 136 |
foreach ($interceptorInitializer->getPreInterceptors() as $preInterceptor) { |
|---|
| 137 |
$preInterceptor->preProcess($this->request, $this->session, $this->response); |
|---|
| 138 |
if ($this->request->isCancelled() === true) { |
|---|
| 139 |
$this->response->send(); |
|---|
| 140 |
return; |
|---|
| 141 |
} |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
if (null !== $this->websiteCacheFactory) { |
|---|
| 145 |
$processor = $this->websiteCacheFactory->configure($processor); |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
$processor->process(); |
|---|
| 149 |
if ($this->request->isCancelled() === false) { |
|---|
| 150 |
foreach ($interceptorInitializer->getPostInterceptors() as $postInterceptor) { |
|---|
| 151 |
$postInterceptor->postProcess($this->request, $this->session, $this->response); |
|---|
| 152 |
if ($this->request->isCancelled() === true) { |
|---|
| 153 |
break; |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
$this->response->send(); |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
?> |
|---|