1 | <?php |
||
32 | class Application |
||
33 | { |
||
34 | /** @var Container $registry */ |
||
35 | private $treasureChest; |
||
36 | |||
37 | /** @var string $configFolder */ |
||
38 | private $configFolder = 'config'; |
||
39 | |||
40 | /** @var string $environment */ |
||
41 | private $environment = 'production'; |
||
42 | |||
43 | /** |
||
44 | * There be nay feckin wi' constructors on board this ship |
||
45 | * There be nay copyin' o' th'ship either |
||
46 | * This ship is a singleton! |
||
47 | */ |
||
48 | private function __construct(){} |
||
49 | |||
50 | private function __clone(){} |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Ahoy! There nay be boardin without yer configuration |
||
55 | * |
||
56 | * @param array $config |
||
|
|||
57 | * @return Application |
||
58 | */ |
||
59 | 10 | public static function ahoy() |
|
75 | |||
76 | |||
77 | /** |
||
78 | * |
||
79 | * T' the high seas! Garrr! |
||
80 | * |
||
81 | * @return bool |
||
82 | * @throws \Exception |
||
83 | */ |
||
84 | 8 | public function setSail() |
|
85 | { |
||
86 | // load in the config and set up the dependency injection container |
||
87 | 8 | $env = new Environment($_SERVER); |
|
88 | 8 | $request = ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); |
|
89 | 8 | $router = $this->treasureChest[Router::class] = new Router(); |
|
90 | |||
91 | 8 | $config = $env->fetchConfig($this->configFolder, $this->environment); |
|
92 | 8 | $config[Environment::class] = $env; |
|
93 | 8 | $config[SiteConfig::class] = new SiteConfig($config, $env); |
|
94 | |||
95 | 8 | $package = new ApplicationPackage($config, $router); |
|
96 | 8 | $package->addToContainer($this->treasureChest); |
|
97 | |||
98 | 8 | if ($this->isMultilingual()) { |
|
99 | |||
100 | try { |
||
101 | 7 | $request = $this->i18nRequestCheck($request); |
|
102 | 7 | $response = $router->dispatch($request); |
|
103 | } catch (NotFoundException $e) { |
||
104 | $response = new RedirectResponse($e->getMessage()); |
||
105 | if ($e->getRequest()->getMethod() !== 'GET') { |
||
106 | 7 | $response = $router->dispatch($request); |
|
107 | } |
||
108 | } |
||
109 | |||
110 | } else { |
||
111 | 1 | $request = $this->i18nRequestCheck($request, false); |
|
112 | 1 | $response = $router->dispatch($request); |
|
113 | } |
||
114 | |||
115 | 8 | (new SapiEmitter)->emit($response); |
|
116 | |||
117 | 8 | return true; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @return bool |
||
122 | */ |
||
123 | 8 | public function isMultilingual(): bool |
|
128 | |||
129 | |||
130 | /** |
||
131 | * @param ServerRequestInterface $request |
||
132 | * @param bool $handle |
||
133 | * @return ServerRequestInterface |
||
134 | * @throws NotFoundException |
||
135 | */ |
||
136 | 8 | private function i18nRequestCheck(ServerRequestInterface $request, bool $handle = true): ServerRequestInterface |
|
149 | |||
150 | /** |
||
151 | * @return Container |
||
152 | */ |
||
153 | 1 | public function getContainer(): Container |
|
157 | |||
158 | /** |
||
159 | * @param string $configFolder |
||
160 | */ |
||
161 | 8 | public function setConfigFolder(string $configFolder) |
|
165 | |||
166 | /** |
||
167 | * @param string $environment |
||
168 | */ |
||
169 | 1 | public function setEnvironment(string $environment) |
|
173 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.