/** * Paint blue screen. * @param \Exception * @return void * @ignore internal */ public static function _paintBlueScreen(\Exception $exception) { $internals = array(); foreach (array('Nette\\Object', 'Nette\\ObjectMixin') as $class) { if (class_exists($class, FALSE)) { $rc = new \ReflectionClass($class); $internals[$rc->getFileName()] = TRUE; } } if (class_exists('Nette\\Environment', FALSE)) { $application = Environment::getServiceLocator()->hasService('Nette\\Application\\Application', TRUE) ? Environment::getServiceLocator()->getService('Nette\\Application\\Application') : NULL; } require __DIR__ . '/templates/bluescreen.phtml'; }
/** * Paint blue screen. * @param \Exception * @return void * @ignore internal */ public static function _paintBlueScreen(\Exception $exception) { if (class_exists('Nette\\Environment', FALSE)) { $application = Environment::getServiceLocator()->hasService('Nette\\Application\\Application', TRUE) ? Environment::getServiceLocator()->getService('Nette\\Application\\Application') : NULL; } require __DIR__ . '/templates/bluescreen.phtml'; }
/** * Loads global configuration from file and process it. * @param string|Nette\Config\Config file name or Config object * @return Nette\Config\Config */ public function loadConfig($file) { $name = Environment::getName(); if ($file instanceof Nette\Config\Config) { $config = $file; $file = NULL; } else { if ($file === NULL) { $file = $this->defaultConfigFile; } $file = Environment::expand($file); $config = Nette\Config\Config::fromFile($file, $name); } // process environment variables if ($config->variable instanceof Nette\Config\Config) { foreach ($config->variable as $key => $value) { Environment::setVariable($key, $value); } } // expand variables $iterator = new \RecursiveIteratorIterator($config); foreach ($iterator as $key => $value) { $tmp = $iterator->getDepth() ? $iterator->getSubIterator($iterator->getDepth() - 1)->current() : $config; $tmp[$key] = Environment::expand($value); } // process services $runServices = array(); $locator = Environment::getServiceLocator(); if ($config->service instanceof Nette\Config\Config) { foreach ($config->service as $key => $value) { $key = strtr($key, '-', '\\'); // limited INI chars if (is_string($value)) { $locator->removeService($key); $locator->addService($key, $value); } else { if ($value->factory) { $locator->removeService($key); $locator->addService($key, $value->factory, isset($value->singleton) ? $value->singleton : TRUE, (array) $value->option); } if ($value->run) { $runServices[] = $key; } } } } // process ini settings if (!$config->php) { // backcompatibility $config->php = $config->set; unset($config->set); } if ($config->php instanceof Nette\Config\Config) { if (PATH_SEPARATOR !== ';' && isset($config->php->include_path)) { $config->php->include_path = str_replace(';', PATH_SEPARATOR, $config->php->include_path); } foreach (clone $config->php as $key => $value) { // flatten INI dots if ($value instanceof Nette\Config\Config) { unset($config->php->{$key}); foreach ($value as $k => $v) { $config->php->{"{$key}.{$k}"} = $v; } } } foreach ($config->php as $key => $value) { $key = strtr($key, '-', '.'); // backcompatibility if (!is_scalar($value)) { throw new \InvalidStateException("Configuration value for directive '{$key}' is not scalar."); } if ($key === 'date.timezone') { // PHP bug #47466 date_default_timezone_set($value); } if (function_exists('ini_set')) { ini_set($key, $value); } else { switch ($key) { case 'include_path': set_include_path($value); break; case 'iconv.internal_encoding': iconv_set_encoding('internal_encoding', $value); break; case 'mbstring.internal_encoding': mb_internal_encoding($value); break; case 'date.timezone': date_default_timezone_set($value); break; case 'error_reporting': error_reporting($value); break; case 'ignore_user_abort': ignore_user_abort($value); break; case 'max_execution_time': set_time_limit($value); break; default: if (ini_get($key) != $value) { // intentionally == throw new \NotSupportedException('Required function ini_set() is disabled.'); } } } } } // define constants if ($config->const instanceof Nette\Config\Config) { foreach ($config->const as $key => $value) { define($key, $value); } } // set modes if (isset($config->mode)) { foreach ($config->mode as $mode => $state) { Environment::setMode($mode, $state); } } // auto-start services foreach ($runServices as $name) { $locator->getService($name); } return $config; }
/** * Gets the service locator (experimental). * @return Nette\IServiceLocator */ public final function getServiceLocator() { if ($this->serviceLocator === NULL) { $this->serviceLocator = new Nette\ServiceLocator(Environment::getServiceLocator()); foreach ($this->defaultServices as $name => $service) { if (!$this->serviceLocator->hasService($name)) { $this->serviceLocator->addService($name, $service); } } } return $this->serviceLocator; }