1 | <?php |
||
28 | class Application |
||
29 | { |
||
30 | /** @var Container $registry */ |
||
31 | private $treasureChest; |
||
32 | |||
33 | /** @var string $configFolder */ |
||
34 | private $configFolder = 'config'; |
||
35 | |||
36 | /** @var string $environment */ |
||
37 | private $environment = 'production'; |
||
38 | |||
39 | /** |
||
40 | * There be nay feckin wi' constructors on board this ship |
||
41 | * There be nay copyin' o' th'ship either |
||
42 | * This ship is a singleton! |
||
43 | */ |
||
44 | private function __construct(){} |
||
45 | |||
46 | public function __clone(){} |
||
47 | |||
48 | |||
49 | /** |
||
50 | * Ahoy! There nay be boardin without yer configuration |
||
51 | * |
||
52 | * @param array $config |
||
|
|||
53 | * @return Application |
||
54 | */ |
||
55 | 10 | public static function ahoy() |
|
68 | |||
69 | |||
70 | /** |
||
71 | * |
||
72 | * T' the high seas! Garrr! |
||
73 | * |
||
74 | * @return bool |
||
75 | * @throws \Exception |
||
76 | */ |
||
77 | 8 | public function setSail() |
|
78 | { |
||
79 | // load in the config and set up the dependency injection container |
||
80 | 8 | $env = new Environment($_SERVER); |
|
81 | 8 | $request = ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); |
|
82 | 8 | $router = $this->treasureChest[Router::class] = new Router(); |
|
83 | 8 | $config = $env->fetchConfig($this->configFolder, $this->environment); |
|
84 | 8 | $package = new ApplicationPackage($config, $router); |
|
85 | 8 | $package->addToContainer($this->treasureChest); |
|
86 | |||
87 | 8 | if ($this->isMultilingual()) { |
|
88 | |||
89 | try { |
||
90 | 7 | $request = $this->i18nRequestCheck($request); |
|
91 | 6 | $response = $router->dispatch($request); |
|
92 | 1 | } catch (NotFoundException $e) { |
|
93 | 7 | $response = new RedirectResponse($e->getMessage()); |
|
94 | } |
||
95 | |||
96 | } else { |
||
97 | 1 | $request = $this->i18nRequestCheck($request, false); |
|
98 | 1 | $response = $router->dispatch($request); |
|
99 | } |
||
100 | |||
101 | 8 | (new SapiEmitter)->emit($response); |
|
102 | |||
103 | 8 | return true; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | 8 | public function isMultilingual(): bool |
|
114 | |||
115 | |||
116 | /** |
||
117 | * @param ServerRequestInterface $request |
||
118 | * @param bool $handle |
||
119 | * @return ServerRequestInterface |
||
120 | * @throws NotFoundException |
||
121 | */ |
||
122 | 8 | private function i18nRequestCheck(ServerRequestInterface $request, bool $handle = true): ServerRequestInterface |
|
123 | { |
||
124 | 8 | $i18n = $this->treasureChest->get('i18n'); |
|
125 | 8 | $translator = $this->treasureChest->get('translator'); |
|
126 | 8 | $i18nHandler = new I18nHandler($translator, $i18n['supported_locales']); |
|
127 | 8 | if ($handle) { |
|
128 | 7 | $request = $i18nHandler->handleI18n($request); |
|
129 | } else { |
||
130 | 1 | $request = $i18nHandler->removeI18n($request); |
|
131 | } |
||
132 | |||
133 | 7 | return $request; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * @return Container |
||
138 | */ |
||
139 | 1 | public function getContainer(): Container |
|
143 | |||
144 | /** |
||
145 | * @param string $configFolder |
||
146 | */ |
||
147 | 8 | public function setConfigFolder(string $configFolder) |
|
151 | |||
152 | /** |
||
153 | * @param string $environment |
||
154 | */ |
||
155 | 1 | public function setEnvironment(string $environment) |
|
159 | } |
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.