PhileCMS /
Phile
| 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; |
||
| 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); |
||
| 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')); |
||
| 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 { |
||
|
0 ignored issues
–
show
|
|||
| 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 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.