allejo /
bzion
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file contains functionality relating Symfony2 components such as the template engine, requests, and sessions |
||
| 4 | * |
||
| 5 | * @package BZiON |
||
| 6 | * @license https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3 |
||
| 7 | */ |
||
| 8 | |||
| 9 | use BZIon\Cache\ModelCache; |
||
| 10 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
| 11 | use Symfony\Component\EventDispatcher\EventDispatcher; |
||
| 12 | use Symfony\Component\Form\FormFactory; |
||
| 13 | use Symfony\Component\HttpFoundation\Request; |
||
| 14 | use Symfony\Component\HttpFoundation\Session\Session; |
||
| 15 | use Symfony\Component\HttpFoundation\Session\SessionInterface; |
||
| 16 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Class Service |
||
| 20 | */ |
||
| 21 | abstract class Service |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Symfony's URL Generator |
||
| 25 | * @var UrlGeneratorInterface; |
||
| 26 | */ |
||
| 27 | private static $generator; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Symfony's Request class |
||
| 31 | * @var Request |
||
| 32 | */ |
||
| 33 | private static $request; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Symfony's FormFactory |
||
| 37 | * @var FormFactory |
||
| 38 | */ |
||
| 39 | private static $formFactory; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The kernel's environment (prod, debug, profile or test) |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | private static $environment; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The model memory cache |
||
| 49 | * @var ModelCache |
||
| 50 | */ |
||
| 51 | private static $modelCache; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The AppKernel's container |
||
| 55 | * @var AppKernel |
||
| 56 | */ |
||
| 57 | private static $kernel; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param Request $request |
||
| 61 | */ |
||
| 62 | 23 | public static function setRequest($request) |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 63 | { |
||
| 64 | 23 | self::$request = $request; |
|
| 65 | 23 | } |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @return Request |
||
| 69 | */ |
||
| 70 | 23 | public static function getRequest() |
|
| 71 | { |
||
| 72 | 23 | if (!self::$request) { |
|
| 73 | $request = Request::createFromGlobals(); |
||
| 74 | $request->setSession(self::getNewSession()); |
||
| 75 | self::setRequest($request); |
||
| 76 | } |
||
| 77 | |||
| 78 | 23 | return self::$request; |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Sets the URL Generator. |
||
| 83 | * @param UrlGeneratorInterface $generator |
||
| 84 | * @return void |
||
| 85 | */ |
||
| 86 | 1 | public static function setGenerator($generator) |
|
| 87 | { |
||
| 88 | 1 | self::$generator = $generator; |
|
| 89 | 1 | } |
|
| 90 | |||
| 91 | /** |
||
| 92 | * @return UrlGeneratorInterface |
||
| 93 | */ |
||
| 94 | 1 | public static function getGenerator() |
|
| 95 | { |
||
| 96 | 1 | return self::$generator; |
|
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Gets a parameter |
||
| 101 | * |
||
| 102 | * @param string $name The parameter name |
||
| 103 | * @return mixed The parameter value |
||
| 104 | */ |
||
| 105 | 76 | public static function getParameter($name) |
|
| 106 | { |
||
| 107 | 76 | return self::getContainer()->getParameter($name); |
|
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param SessionInterface $session |
||
| 112 | */ |
||
| 113 | public static function setSession($session) |
||
| 114 | { |
||
| 115 | self::getRequest()->setSession($session); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @return SessionInterface |
||
| 120 | */ |
||
| 121 | public static function getSession() |
||
| 122 | { |
||
| 123 | return self::getRequest()->getSession(); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Create a new session |
||
| 128 | * @return Session |
||
| 129 | */ |
||
| 130 | public static function getNewSession() |
||
| 131 | { |
||
| 132 | $newSession = new Session(); |
||
| 133 | $newSession->start(); |
||
| 134 | |||
| 135 | return $newSession; |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @return FormFactory |
||
| 140 | */ |
||
| 141 | 1 | public static function getFormFactory() |
|
| 142 | { |
||
| 143 | 1 | return self::$formFactory; |
|
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @param FormFactory $formFactory |
||
| 148 | */ |
||
| 149 | 23 | public static function setFormFactory($formFactory) |
|
| 150 | { |
||
| 151 | 23 | self::$formFactory = $formFactory; |
|
| 152 | 23 | } |
|
| 153 | |||
| 154 | /** |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | 1 | public static function getEnvironment() |
|
| 158 | { |
||
| 159 | 1 | return self::$environment; |
|
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $environment |
||
| 164 | */ |
||
| 165 | 1 | public static function setEnvironment($environment) |
|
| 166 | { |
||
| 167 | 1 | self::$environment = $environment; |
|
| 168 | 1 | } |
|
| 169 | |||
| 170 | /** |
||
| 171 | * @return ModelCache |
||
| 172 | */ |
||
| 173 | 76 | public static function getModelCache() |
|
| 174 | { |
||
| 175 | 76 | return self::$modelCache; |
|
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @param ModelCache $modelCache |
||
| 180 | */ |
||
| 181 | 1 | public static function setModelCache($modelCache) |
|
| 182 | { |
||
| 183 | 1 | self::$modelCache = $modelCache; |
|
| 184 | 1 | } |
|
| 185 | |||
| 186 | /** |
||
| 187 | * @return string[][] |
||
| 188 | */ |
||
| 189 | 76 | public static function getSiteThemes() |
|
| 190 | { |
||
| 191 | 76 | return self::getParameter('bzion.site.themes'); |
|
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return string |
||
| 196 | */ |
||
| 197 | 1 | public static function getDefaultSiteTheme() |
|
| 198 | { |
||
| 199 | 1 | $themes = self::getSiteThemes(); |
|
| 200 | 1 | ||
| 201 | return $themes[0]['slug']; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | 1 | * @return ContainerInterface |
|
| 206 | */ |
||
| 207 | 1 | public static function getContainer() |
|
| 208 | { |
||
| 209 | return self::$kernel->getContainer(); |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | 76 | * @param $kernel |
|
| 214 | */ |
||
| 215 | 76 | public static function setKernel($kernel) |
|
| 216 | { |
||
| 217 | self::$kernel = $kernel; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return EventDispatcher |
||
| 222 | */ |
||
| 223 | public static function getDispatcher() |
||
| 224 | { |
||
| 225 | return self::getContainer()->get('event_dispatcher'); |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return bool |
||
| 230 | */ |
||
| 231 | public static function isDebug() |
||
| 232 | { |
||
| 233 | return self::getParameter('kernel.debug'); |
||
| 234 | } |
||
| 235 | } |
||
| 236 |