| 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::util::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 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | protected $websiteInitializer; |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | protected $request; |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | protected $session; |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | protected $response; |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | protected $websiteCacheFactory; |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 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 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 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 | $fqClassName = stubRegistry::getConfig(stubSession::CLASS_REGISTRY_KEY, 'net::stubbles::ipo::session::stubPHPSession'); |
|---|
| 91 | $className = stubClassLoader::getNonQualifiedClassName($fqClassName); |
|---|
| 92 | if (class_exists($className, false) === false) { |
|---|
| 93 | stubClassLoader::load($fqClassName); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | $this->session = new $className($this->request, stubRegistry::getConfig(stubSession::NAME_REGISTRY_KEY, stubSession::DEFAULT_SESSION_NAME)); |
|---|
| 97 | if (($this->session instanceof stubSession) === false) { |
|---|
| 98 | throw new stubRuntimeException('Configured session class is not an instance of net::stubbles::ipo::session::stubSession.'); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | $this->response = new stubBaseResponse(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | public function setWebsiteCacheFactory(stubWebsiteCacheFactory $websiteCacheFactory) |
|---|
| 110 | { |
|---|
| 111 | $this->websiteCacheFactory = $websiteCacheFactory; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | public function process() |
|---|
| 118 | { |
|---|
| 119 | $processorResolverFactory = $this->websiteInitializer->getProcessorResolverFactory(); |
|---|
| 120 | $processorResolverFactory->init(); |
|---|
| 121 | $processor = $processorResolverFactory->getResolver()->resolve($this->request, $this->session, $this->response); |
|---|
| 122 | if ($processor->forceSSL() === true && $processor->isSSL() === false) { |
|---|
| 123 | $this->response->addHeader('Location', 'https://' . $this->request->getURI()); |
|---|
| 124 | $this->request->cancel(); |
|---|
| 125 | $this->response->send(); |
|---|
| 126 | return; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | $interceptorInitializer = $this->websiteInitializer->getInterceptorInitializer(); |
|---|
| 130 | $interceptorInitializer->setDescriptor($processor->getInterceptorDescriptor()); |
|---|
| 131 | $interceptorInitializer->init(); |
|---|
| 132 | foreach ($interceptorInitializer->getPreInterceptors() as $preInterceptor) { |
|---|
| 133 | $preInterceptor->preProcess($this->request, $this->session, $this->response); |
|---|
| 134 | if ($this->request->isCancelled() === true) { |
|---|
| 135 | $this->response->send(); |
|---|
| 136 | return; |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | if (null !== $this->websiteCacheFactory) { |
|---|
| 141 | $processor = $this->websiteCacheFactory->configure($processor); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | $processor->process(); |
|---|
| 145 | if ($this->request->isCancelled() === false) { |
|---|
| 146 | foreach ($interceptorInitializer->getPostInterceptors() as $postInterceptor) { |
|---|
| 147 | $postInterceptor->postProcess($this->request, $this->session, $this->response); |
|---|
| 148 | if ($this->request->isCancelled() === true) { |
|---|
| 149 | break; |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | $this->response->send(); |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | ?> |
|---|