/** * Bootstrap the application. */ protected function bootstrap() { // Read all config files $config = new Repository($this->loadConfigFiles()); // Register the configuration instance for later use. // Note that Slim framework already used a service key named 'settings' for // accessing the framework settings. Here, we will use a separate key for // the application configurations. If you want to reuse the service key, // you should merge the framework settings with the application configurations. $container = $this->getContainer(); $container['config'] = function () use($config) { return $config; }; date_default_timezone_set($config['app.timezone']); mb_internal_encoding('UTF-8'); // Register route handler strategy $container['foundHandler'] = function () { return new \Slim\Handlers\Strategies\RequestResponseArgs(); }; // Register a logger used in the application $container['logger'] = function () use($container) { $logger = new \Monolog\Logger('logger'); $logger->pushProcessor(new \Monolog\Processor\WebProcessor()); $logger->pushHandler(new \Monolog\Handler\StreamHandler($container['path.storage'] . 'logs' . DIRECTORY_SEPARATOR . 'error.log')); return $logger; }; // Register 500 System Error handler $container['errorHandler'] = function () use($container) { $errorHandler = new \Core\Handlers\Error($container['config']['app.debug']); if (isset($container['logger'])) { $errorHandler->setLogger($container['logger']); } return $errorHandler; }; // Register 404 Not Found handler $container['notFoundHandler'] = function () { return new \Core\Handlers\NotFound(); }; // Register 405 Method Not Allowed handler $container['notAllowedHandler'] = function () { return new \Core\Handlers\NotAllowed(); }; // Register the specified providers. $providers = $config['app.providers']; foreach ($providers as $provider) { $container->register(new $provider()); } // Register facades which are shortcuts // for accessing registered services. Facade::setContainer($container); }
$app = new Application(); $app->instance('app', $app); //-------------------------------------------------------------------------- // Detect The Application Environment //-------------------------------------------------------------------------- $env = $app->detectEnvironment(array('local' => array('darkstar'))); //-------------------------------------------------------------------------- // Bind Paths //-------------------------------------------------------------------------- $paths = array('base' => ROOTDIR, 'app' => APPDIR, 'public' => PUBLICDIR, 'storage' => STORAGE_PATH); $app->bindInstallPaths($paths); //-------------------------------------------------------------------------- // Load The Framework Facades //-------------------------------------------------------------------------- Facade::clearResolvedInstances(); Facade::setFacadeApplication($app); //-------------------------------------------------------------------------- // Register Facade Aliases To Full Classes //-------------------------------------------------------------------------- $app->registerCoreContainerAliases(); //-------------------------------------------------------------------------- // Register Application Exception Handling //-------------------------------------------------------------------------- $app->startExceptionHandling(); if ($env != 'testing') { ini_set('display_errors', 'Off'); } //-------------------------------------------------------------------------- // Load The Configuration //-------------------------------------------------------------------------- foreach (glob(app_path() . 'Config/*.php') as $path) {
//-------------------------------------------------------------------------- // Try To Register Again The Config Manager //-------------------------------------------------------------------------- use Config\Repository as ConfigRepository; use Support\Facades\Facade; if (CONFIG_STORE == 'database') { // Get the Database Connection instance. $connection = $app['db']->connection(); // Get a fresh Config Loader instance. $loader = $app->getConfigLoader(); // Setup Database Connection instance. $loader->setConnection($connection); // Refresh the Application's Config instance. $app->instance('config', $config = new ConfigRepository($loader)); // Make the Facade to refresh its information. Facade::clearResolvedInstance('config'); } else { if (CONFIG_STORE != 'files') { throw new \InvalidArgumentException('Invalid Config Store type.'); } } //-------------------------------------------------------------------------- // Start the Legacy Session //-------------------------------------------------------------------------- use Helpers\Session as LegacySession; LegacySession::init(); //-------------------------------------------------------------------------- // Boot Stage Customization //-------------------------------------------------------------------------- /** * Create a constant for the URL of the site.
/** * Refresh the bound request instance in the container. * * @param \Http\Request $request * @return void */ protected function refreshRequest(Request $request) { $this->instance('request', $request); Facade::clearResolvedInstance('request'); }