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