1 | <?php |
||||
2 | /** |
||||
3 | * Bootstraps the Phile-core |
||||
4 | * |
||||
5 | * There's no need to make changes here in an ordinary Phile installation. |
||||
6 | * It allows advanced configuration options if necessary. |
||||
7 | * |
||||
8 | * @author PhileCMS |
||||
9 | * @link https://github.com/PhileCMS/Phile |
||||
10 | * @license http://opensource.org/licenses/MIT |
||||
11 | */ |
||||
12 | |||||
13 | |||||
14 | /** |
||||
15 | * Set global definitions |
||||
16 | */ |
||||
17 | require_once 'constants.php'; |
||||
18 | |||||
19 | /** |
||||
20 | * Setup container |
||||
21 | */ |
||||
22 | require 'container.php'; |
||||
23 | $container = Phile\Core\Container::getInstance(); |
||||
24 | |||||
25 | /** |
||||
26 | * Register plugin directories |
||||
27 | * |
||||
28 | * Allows autoloading from plugin-directories and early usage in config.php |
||||
29 | * |
||||
30 | * @var \Phile\Plugin\PluginRepository $plugins |
||||
31 | */ |
||||
32 | $plugins = $container->get('Phile_Plugins'); |
||||
33 | $plugins->addDirectory(PLUGINS_DIR); |
||||
34 | |||||
35 | /** |
||||
36 | * Setup global application-object |
||||
37 | * |
||||
38 | * @var \Phile\Phile $app |
||||
39 | */ |
||||
40 | $app = $container->get('Phile_App'); |
||||
41 | |||||
42 | /** |
||||
43 | * Define the bootstrap process |
||||
44 | */ |
||||
45 | use Phile\Core\Bootstrap; |
||||
46 | use Phile\Core\Config; |
||||
47 | use Phile\Core\Event; |
||||
0 ignored issues
–
show
|
|||||
48 | use Phile\Core\Registry; |
||||
49 | |||||
50 | $app->addBootstrap(function (Event $eventBus, Config $config) use ($plugins): void { |
||||
51 | // Load configuration files into global $config configuration |
||||
52 | $configDir = $config->get('config_dir'); |
||||
53 | Bootstrap::loadConfiguration($configDir . 'defaults.php', $config); |
||||
54 | Bootstrap::loadConfiguration($configDir . 'config.php', $config); |
||||
55 | |||||
56 | // backwards-compatibility for deprecated global constants set in Config now |
||||
57 | // phpcs:disable PSR1.Files.SideEffects |
||||
58 | defined('CONTENT_DIR') || define('CONTENT_DIR', $config->get('content_dir')); |
||||
59 | defined('CONTENT_EXT') || define('CONTENT_EXT', $config->get('content_ext')); |
||||
60 | // phpcs:enable |
||||
61 | |||||
62 | // Setup core folders |
||||
63 | Bootstrap::setupFolder($config->get('cache_dir'), $config); |
||||
0 ignored issues
–
show
It seems like
$config->get('cache_dir') can also be of type null ; however, parameter $directory of Phile\Core\Bootstrap::setupFolder() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
64 | Bootstrap::setupFolder($config->get('storage_dir'), $config); |
||||
65 | |||||
66 | // backwards-compatibility for deprecated static Event access |
||||
67 | Event::setInstance($eventBus); |
||||
68 | |||||
69 | // Load plug-ins |
||||
70 | $plugins->load($config); |
||||
71 | |||||
72 | // Set error handler |
||||
73 | Bootstrap::setupErrorHandler($config); |
||||
74 | |||||
75 | // Intialize global registry objects |
||||
76 | Registry::set('templateVars', []); |
||||
77 | |||||
78 | // Set additional PHP environment variables from configuration |
||||
79 | date_default_timezone_set($config->get('timezone')); |
||||
0 ignored issues
–
show
It seems like
$config->get('timezone') can also be of type null ; however, parameter $timezoneId of date_default_timezone_set() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
80 | }); |
||||
81 | |||||
82 | /** |
||||
83 | * Add PSR-15 middleware |
||||
84 | */ |
||||
85 | use Phile\Http\MiddlewareQueue; |
||||
86 | |||||
87 | $app->addMiddleware(function (MiddlewareQueue $middleware, Event $eventBus, Config $config) use ($app): void { |
||||
88 | // Inject middleware from Phile-plugins |
||||
89 | $eventBus->trigger('phile.core.middleware.add', ['middleware' => $middleware]); |
||||
90 | |||||
91 | // Add Phile itself as middleware (take request and render output) |
||||
92 | $middleware->add($app); |
||||
93 | }); |
||||
94 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: