1 | <?php declare(strict_types=1); |
||
16 | class Application |
||
17 | { |
||
18 | /** @var Container $container */ |
||
19 | private $container; |
||
20 | |||
21 | /** @var string $configFolder */ |
||
22 | private $configFolder = 'config'; |
||
23 | |||
24 | /** @var string $environment */ |
||
25 | private $environment = 'production'; |
||
26 | |||
27 | /** |
||
28 | * There be nay feckin wi' constructors on board this ship |
||
29 | * There be nay copyin' o' th'ship either |
||
30 | * This ship is a singleton! |
||
31 | */ |
||
32 | 1 | private function __construct(){ |
|
33 | 1 | } |
|
34 | private function __clone(){} |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Ahoy! There nay be boardin without yer configuration |
||
39 | * |
||
40 | * @param array $config |
||
|
|||
41 | * @return Application |
||
42 | */ |
||
43 | 11 | public static function ahoy() |
|
44 | { |
||
45 | 11 | static $inst = null; |
|
46 | 11 | if ($inst === null) { |
|
47 | 1 | $inst = new Application(); |
|
48 | |||
49 | 1 | $factories = require './factories.php'; |
|
50 | $inst->container = new Container($factories); |
||
51 | |||
52 | $session = SessionManager::getInstance(); |
||
53 | SessionManager::sessionStart('app'); |
||
54 | $inst->container[SessionManager::class] = $session; |
||
55 | |||
56 | $env = getenv('APPLICATION_ENV'); |
||
57 | |||
58 | if ($env) { |
||
59 | $inst->setEnvironment($env); |
||
60 | } |
||
61 | } |
||
62 | 10 | return $inst; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Use this to bootstrap Bone without dispatching any request |
||
67 | * i.e. for when using the framework in a CLI application |
||
68 | */ |
||
69 | 9 | public function bootstrap(): Container |
|
70 | { |
||
71 | 9 | $env = new Environment($_SERVER); |
|
72 | 9 | $router = $this->container[Router::class] = new Router(); |
|
73 | 9 | $config = $env->fetchConfig($this->configFolder, $this->environment); |
|
74 | 9 | $config[Environment::class] = $env; |
|
75 | 9 | $config[SiteConfig::class] = new SiteConfig($config, $env); |
|
76 | |||
77 | 9 | $packageManager = $this->container->get(PackageManager::class); |
|
78 | |||
79 | |||
80 | $package = new ApplicationPackage($config, $router); |
||
81 | $package->addToContainer($this->container); |
||
82 | |||
83 | return $this->container; |
||
84 | } |
||
85 | |||
86 | |||
87 | /** |
||
88 | * |
||
89 | * T' the high seas! Garrr! |
||
90 | * |
||
91 | * @return bool |
||
92 | * @throws \Exception |
||
93 | */ |
||
94 | 8 | public function setSail() |
|
95 | { |
||
96 | // load in the config and set up the dependency injection container |
||
97 | 8 | $this->bootstrap(); |
|
98 | $request = ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); |
||
99 | /** @var RequestHandlerInterface $stack */ |
||
100 | $stack = $this->container->get(Stack::class); |
||
101 | $response = $stack->handle($request); |
||
102 | |||
103 | (new SapiEmitter)->emit($response); |
||
104 | |||
105 | return true; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return Container |
||
110 | */ |
||
111 | 1 | public function getContainer(): Container |
|
115 | |||
116 | /** |
||
117 | * @param string $configFolder |
||
118 | */ |
||
119 | 9 | public function setConfigFolder(string $configFolder) |
|
123 | |||
124 | /** |
||
125 | * @param string $environment |
||
126 | */ |
||
127 | public function setEnvironment(string $environment) |
||
131 | } |
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.