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: // process ini settings
140: if (!$config->php) { // backcompatibility
141: $config->php =
$config->set;
142: unset($config->set);
146: if (PATH_SEPARATOR !==
';' &&
isset($config->php->include_path)) {
147: $config->php->include_path =
str_replace(';', PATH_SEPARATOR, $config->php->include_path);
150: foreach ($config->php as $key =>
$value) { // flatten INI dots
152: unset($config->php->$key);
153: foreach ($value as $k =>
$v) {
154: $config->php->{"$key.$k"} =
$v;
159: foreach ($config->php as $key =>
$value) {
160: $key =
strtr($key, '-', '.'); // backcompatibility
170: case 'include_path':
173: case 'iconv.internal_encoding':
176: case 'mbstring.internal_encoding':
179: case 'date.timezone':
182: case 'error_reporting':
185: case 'ignore_user_abort':
188: case 'max_execution_time':
192: if (ini_get($key) !=
$value) { // intentionally ==
202: foreach ($config->const as $key =>
$value) {
203: define($key, $value);
208: if (isset($config->mode)) {
209: foreach($config->mode as $mode =>
$state) {
214: // auto-start services
215: foreach ($runServices as $name) {
216: $locator->getService($name);
225: /********************* service factories ****************d*g**/
230: * Get initial instance of service locator.
231: * @return IServiceLocator
237: $locator->addService($name, $service);
245: * @return ICacheStorage
255: * @return RobotLoader
261: //$loader->setCache(Environment::getCache('Nette.RobotLoader'));
263: $loader->addDirectory($dirs);
264: $loader->register();