1 | <?php |
||
22 | class AppKernel extends Kernel |
||
23 | { |
||
24 | private $request = null; |
||
25 | |||
26 | 1 | public function registerContainerConfiguration(LoaderInterface $loader) |
|
30 | |||
31 | 1 | public function registerBundles() |
|
32 | { |
||
33 | $bundles = array( |
||
34 | 1 | new BZIon\Config\ConfigBundle(), |
|
35 | 1 | new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), |
|
36 | 1 | new Symfony\Bundle\MonologBundle\MonologBundle(), |
|
37 | 1 | new Symfony\Bundle\TwigBundle\TwigBundle(), |
|
38 | 1 | new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), |
|
39 | 1 | new Liip\ImagineBundle\LiipImagineBundle(), |
|
40 | 1 | new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), |
|
41 | 1 | new Nelmio\ApiDocBundle\NelmioApiDocBundle(), |
|
42 | ); |
||
43 | |||
44 | 1 | if ($this->getEnvironment() == 'profile') { |
|
45 | $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); |
||
46 | $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); |
||
47 | $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); |
||
48 | } |
||
49 | |||
50 | 1 | return $bundles; |
|
51 | } |
||
52 | |||
53 | 1 | public function boot() |
|
54 | { |
||
55 | 1 | Service::setKernel($this); |
|
56 | |||
57 | 1 | parent::boot(); |
|
58 | |||
59 | 1 | if (!$this->container->getParameter('bzion.miscellaneous.development')) { |
|
60 | if ($this->getEnvironment() != 'prod' || $this->isDebug()) { |
||
61 | throw new ForbiddenDeveloperAccessException( |
||
62 | 'You are not allowed to access this page in a non-production ' . |
||
63 | 'environment. Please change the "development" configuration ' . |
||
64 | 'value and clear the cache before proceeding.' |
||
65 | ); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | 1 | if (in_array($this->getEnvironment(), array('profile', 'dev'), true)) { |
|
70 | Debug::enable(); |
||
71 | } |
||
72 | |||
73 | 1 | Service::setGenerator($this->container->get('router')->getGenerator()); |
|
74 | 1 | Service::setEnvironment($this->getEnvironment()); |
|
75 | 1 | Service::setModelCache(new ModelCache()); |
|
76 | |||
77 | // Ratchet doesn't support PHP's native session storage, so use our own |
||
78 | // if we need it |
||
79 | 1 | if (Service::getParameter('bzion.features.websocket.enabled') && |
|
80 | 1 | $this->getEnvironment() !== 'test') { |
|
81 | $storage = new NativeSessionStorage(array(), new DatabaseSessionHandler()); |
||
82 | $session = new Session($storage); |
||
83 | Service::getContainer()->set('session', $session); |
||
84 | } |
||
85 | |||
86 | 1 | Notification::initializeAdapters(); |
|
87 | 1 | } |
|
88 | |||
89 | /** |
||
90 | * Find out whether the `dev` or the `profile` environment should be used |
||
91 | * for development, depending on the existance of the profiler bundle |
||
92 | * |
||
93 | * @return string The suggested kernel environment |
||
94 | */ |
||
95 | public static function guessDevEnvironment() |
||
104 | |||
105 | 23 | public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) |
|
106 | { |
||
107 | 23 | if (false === $this->booted) { |
|
108 | 1 | $this->boot(); |
|
109 | } |
||
110 | |||
111 | 23 | if ($catch && !$this->isDebug()) { |
|
112 | try { |
||
113 | 23 | return $this->handleRaw($request, $type, $catch); |
|
114 | 1 | } catch (Exception $e) { |
|
115 | 1 | return $this->handleException($e, $request, $type); |
|
116 | } |
||
117 | } else { |
||
118 | 1 | return $this->handleRaw($request, $type, $catch); |
|
119 | } |
||
120 | } |
||
121 | |||
122 | 23 | private function handleRaw(Request $request, $type = self::MASTER_REQUEST, $catch = true) |
|
155 | |||
156 | /** |
||
157 | * Filters a response object. |
||
158 | * |
||
159 | * @param Response $response A Response instance |
||
160 | * @param Request $request An error message in case the response is not a Response object |
||
161 | * @param int $type The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST) |
||
162 | * |
||
163 | * @return Response The filtered Response instance |
||
164 | */ |
||
165 | 23 | private function filterResponse(Response $response, Request $request, $type) |
|
175 | |||
176 | 23 | public function terminate(Request $request, Response $response) |
|
183 | |||
184 | public function terminateWithException(Exception $exception) |
||
188 | |||
189 | 1 | private function handleException(Exception $e, $request, $type) |
|
219 | } |
||
220 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.