Source for file Configurator.php
Documentation is available at Configurator.php
6: * @copyright Copyright (c) 2004, 2010 David Grudl
7: * @license http://nettephp.com/license Nette license
8: * @link http://nettephp.com
16: * Nette\Environment helper.
18: * @copyright Copyright (c) 2004, 2010 David Grudl
28: 'Nette\Application\Application' =>
'Nette\Application\Application',
29: 'Nette\Web\HttpContext' =>
'Nette\Web\HttpContext',
30: 'Nette\Web\IHttpRequest' =>
'Nette\Web\HttpRequest',
31: 'Nette\Web\IHttpResponse' =>
'Nette\Web\HttpResponse',
32: 'Nette\Web\IUser' =>
'Nette\Web\User',
33: 'Nette\Caching\ICacheStorage' =>
array(__CLASS__
, 'createCacheStorage'),
34: 'Nette\Web\Session' =>
'Nette\Web\Session',
35: 'Nette\Loaders\RobotLoader' =>
array(__CLASS__
, 'createRobotLoader'),
41: * Detect environment mode.
42: * @param string mode name
49: // environment name autodetection
58: // detects production mode by server IP address
59: if (PHP_SAPI ===
'cli') {
62: } elseif (isset($_SERVER['SERVER_ADDR']) ||
isset($_SERVER['LOCAL_ADDR'])) {
63: $addr =
isset($_SERVER['SERVER_ADDR']) ?
$_SERVER['SERVER_ADDR'] :
$_SERVER['LOCAL_ADDR'];
65: // 10.0.0.0/8 Private network
66: // 127.0.0.0/8 Loopback
67: // 169.254.0.0/16 & ::1 Link-Local
68: // 172.16.0.0/12 Private network
69: // 192.168.0.0/16 Private network
70: return $addr !==
'::1' &&
(count($oct) !==
4 ||
($oct[0] !==
'10' &&
$oct[0] !==
'127' &&
($oct[0] !==
'172' ||
$oct[1] <
16 ||
$oct[1] >
31)
71: &&
($oct[0] !==
'169' ||
$oct[1] !==
'254') &&
($oct[0] !==
'192' ||
$oct[1] !==
'168')));
78: return PHP_SAPI ===
'cli';
89: * Loads global configuration from file and process it.
90: * @param string|Nette\Config\Config file name or Config object
102: if ($file ===
NULL) {
109: // process environment variables
111: foreach ($config->variable as $key =>
$value) {
119: $runServices =
array();
122: foreach ($config->service as $key =>
$value) {
123: $key =
strtr($key, '-', '\\'); // limited INI chars
125: $locator->removeService($key);
126: $locator->addService($key, $value);
128: if ($value->factory) {
129: $locator->removeService($key);
130: $locator->addService($key, $value->factory, isset($value->singleton) ?
$value->singleton :
TRUE, (array)
$value->option);
133: $runServices[] =
$key;
139: // check temporary directory - TODO: discuss
141: $dir = Environment::getVariable('tempDir');
142: if ($dir && !(is_dir($dir) && is_writable($dir))) {
143: trigger_error("Temporary directory '$dir' is not writable", E_USER_NOTICE);
147: // process ini settings
148: if (!$config->php) { // backcompatibility
149: $config->php =
$config->set;
150: unset($config->set);
154: if (PATH_SEPARATOR !==
';' &&
isset($config->php->include_path)) {
155: $config->php->include_path =
str_replace(';', PATH_SEPARATOR, $config->php->include_path);
158: foreach ($config->php as $key =>
$value) { // flatten INI dots
160: unset($config->php->$key);
161: foreach ($value as $k =>
$v) {
162: $config->php->{"$key.$k"} =
$v;
167: foreach ($config->php as $key =>
$value) {
168: $key =
strtr($key, '-', '.'); // backcompatibility
178: case 'include_path':
181: case 'iconv.internal_encoding':
184: case 'mbstring.internal_encoding':
187: case 'date.timezone':
190: case 'error_reporting':
193: case 'ignore_user_abort':
196: case 'max_execution_time':
200: if (ini_get($key) !=
$value) { // intentionally ==
210: foreach ($config->const as $key =>
$value) {
211: define($key, $value);
216: if (isset($config->mode)) {
217: foreach($config->mode as $mode =>
$state) {
222: // auto-start services
223: foreach ($runServices as $name) {
224: $locator->getService($name);
233: /********************* service factories ****************d*g**/
238: * Get initial instance of service locator.
239: * @return IServiceLocator
245: $locator->addService($name, $service);
253: * @return ICacheStorage
263: * @return RobotLoader
269: //$loader->setCache(Environment::getCache('Nette.RobotLoader'));
271: $loader->addDirectory($dirs);
272: $loader->register();