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 | public function __construct(){} |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Ahoy! There nay be boardin without yer configuration |
||
50 | * |
||
51 | * @param array $config |
||
|
|||
52 | * @return Application |
||
53 | */ |
||
54 | 1 | public static function ahoy() |
|
68 | |||
69 | |||
70 | /** |
||
71 | * |
||
72 | * T' the high seas! Garrr! |
||
73 | * |
||
74 | * @return bool |
||
75 | * @throws \Exception |
||
76 | */ |
||
77 | public function setSail() |
||
78 | { |
||
79 | // load in the config and set up the dependency injection container |
||
80 | $env = new Environment($_SERVER); |
||
81 | $request = ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); |
||
82 | $router = $this->treasureChest[Router::class] = new Router(); |
||
83 | $config = $env->fetchConfig($this->configFolder, $this->environment); |
||
84 | $package = new ApplicationPackage($config, $router); |
||
85 | $package->addToContainer($this->treasureChest); |
||
86 | if ($this->isMultilingual()) { |
||
87 | try { |
||
88 | $request = $this->i18nRequestCheck($request); |
||
89 | $response = $router->dispatch($request); |
||
90 | } catch (NotFoundException $e) { |
||
91 | $response = new RedirectResponse($e->getMessage()); |
||
92 | } |
||
93 | } else { |
||
94 | $request = $this->i18nRequestCheck($request, false); |
||
95 | $response = $router->dispatch($request); |
||
96 | } |
||
97 | |||
98 | (new SapiEmitter)->emit($response); |
||
99 | |||
100 | return true; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function isMultilingual(): bool |
||
111 | |||
112 | |||
113 | /** |
||
114 | * @param ServerRequestInterface $request |
||
115 | * @param bool $handle |
||
116 | * @return ServerRequestInterface |
||
117 | * @throws NotFoundException |
||
118 | */ |
||
119 | private function i18nRequestCheck(ServerRequestInterface $request, bool $handle = true): ServerRequestInterface |
||
132 | |||
133 | /** |
||
134 | * @return Container |
||
135 | */ |
||
136 | public function getContainer(): Container |
||
140 | |||
141 | /** |
||
142 | * @param string $configFolder |
||
143 | */ |
||
144 | public function setConfigFolder(string $configFolder) |
||
148 | |||
149 | /** |
||
150 | * @param string $environment |
||
151 | */ |
||
152 | 1 | public function setEnvironment(string $environment) |
|
156 | } |
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.