public function marshalConfigKeys() { $config = $this->container->get('config'); $middlewares = $config->get('middleware', []); if (!empty($middlewares)) { foreach ($middlewares as $middleware) { if (is_array($middleware)) { $this->add($middleware[0], $middleware[1]); } else { $this->add($middleware); } } } $dependencies = $config->get('dependencies', []); if (!empty($dependencies)) { $this->container->configure($dependencies); } $files = $config->get('microloader.files', []); if (!empty($files)) { \MicroLoader::addFiles($files); } $session = $config->get('session', []); if (!empty($session)) { Session::register($session); } }
function app($service = \null, $app = 'app') { $container = Container::getInstance($app); if ($service !== \null) { return $container->get($service); } return $container; }
$cachedConfigFile = 'data/cache/app_config.php'; $config = []; if (is_file($cachedConfigFile)) { // Try to load the cached config $config = (include $cachedConfigFile); } else { // Load configuration from autoload path foreach (glob('{application/config/*.php,application/config/modules/*.php}', GLOB_BRACE) as $file) { $config = Utils::merge($config, include $file); } // Cache config if enabled if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) { file_put_contents($cachedConfigFile, '<?php return ' . var_export($config, true) . ';'); } } $container = new Container(); $container->set('config', new Config($config)); /* $container->set('logger', function () { $monolog = new Monolog\Logger('app'); $handler = new Monolog\Handler\StreamHandler('data/log/your.html', Monolog\Logger::DEBUG); $handler->setFormatter(new Monolog\Formatter\HtmlFormatter()); $monolog->pushHandler($handler); return $monolog; }); */ /* $container->set('exception.handler', function () { $whoops = new Whoops\Run(); $whoops->allowQuit(false); $whoops->writeToOutput(false); $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler()); return $whoops; }); */