Source for file Configurator.php
Documentation is available at Configurator.php
6: * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
8: * This source file is subject to the "Nette license" that is bundled
9: * with this package in the file license.txt.
11: * For more information please see http://nettephp.com
13: * @copyright Copyright (c) 2004, 2009 David Grudl
14: * @license http://nettephp.com/license Nette license
15: * @link http://nettephp.com
22: require_once dirname(__FILE__) .
'/Object.php';
27: * Nette\Environment helper.
29: * @author David Grudl
30: * @copyright Copyright (c) 2004, 2009 David Grudl
40: 'Nette\Application\Application' =>
'Nette\Application\Application',
41: 'Nette\Web\IHttpRequest' =>
'Nette\Web\HttpRequest',
42: 'Nette\Web\IHttpResponse' =>
'Nette\Web\HttpResponse',
43: 'Nette\Web\IUser' =>
'Nette\Web\User',
44: 'Nette\Caching\ICacheStorage' =>
array(__CLASS__
, 'createCacheStorage'),
45: 'Nette\Web\Session' =>
'Nette\Web\Session',
51: * Detect environment mode.
52: * @param string mode name
59: // environment name autodetection
68: // detects production mode by server IP address
69: if (PHP_SAPI ===
'cli') {
72: } elseif (isset($_SERVER['SERVER_ADDR']) ||
isset($_SERVER['LOCAL_ADDR'])) {
73: $addr =
isset($_SERVER['SERVER_ADDR']) ?
$_SERVER['SERVER_ADDR'] :
$_SERVER['LOCAL_ADDR'];
75: // 10.0.0.0/8 Private network
76: // 127.0.0.0/8 Loopback
77: // 169.254.0.0/16 & ::1 Link-Local
78: // 172.16.0.0/12 Private network
79: // 192.168.0.0/16 Private network
80: return $addr !==
'::1' &&
(count($oct) !==
4 ||
($oct[0] !==
'10' &&
$oct[0] !==
'127' &&
($oct[0] !==
'172' ||
$oct[1] <
16 ||
$oct[1] >
31)
81: &&
($oct[0] !==
'169' ||
$oct[1] !==
'254') &&
($oct[0] !==
'192' ||
$oct[1] !==
'168')));
88: // Determines whether the debugger is active
90: return (bool)
DEBUG_MODE;
94: // function_exists('DebugBreak');
98: return PHP_SAPI ===
'cli';
109: * Loads global configuration from file and process it.
110: * @param string|Nette\Config\Config file name or Config object
122: if ($file ===
NULL) {
129: // process environment variables
131: foreach ($config->variable as $key =>
$value) {
141: foreach ($config->service as $key =>
$value) {
142: $locator->addService($value, strtr($key, '-', '\\'));
146: // check temporary directory - TODO: discuss
148: $dir = Environment::getVariable('tempDir');
149: if ($dir && !(is_dir($dir) && is_writable($dir))) {
150: trigger_error("Temporary directory '$dir' is not writable", E_USER_NOTICE);
154: // process ini settings
155: if (!$config->php) { // backcompatibility
156: $config->php =
$config->set;
157: unset($config->set);
161: if (PATH_SEPARATOR !==
';' &&
isset($config->php->include_path)) {
162: $config->php->include_path =
str_replace(';', PATH_SEPARATOR, $config->php->include_path);
165: foreach ($config->php as $key =>
$value) { // flatten INI dots
167: unset($config->php->$key);
168: foreach ($value as $k =>
$v) {
169: $config->php->{"$key.$k"} =
$v;
174: foreach ($config->php as $key =>
$value) {
175: $key =
strtr($key, '-', '.'); // backcompatibility
185: case 'include_path':
188: case 'iconv.internal_encoding':
191: case 'mbstring.internal_encoding':
194: case 'date.timezone':
197: case 'error_reporting':
200: case 'ignore_user_abort':
203: case 'max_execution_time':
207: if (ini_get($key) !=
$value) { // intentionally ==
217: foreach ($config->const as $key =>
$value) {
218: define($key, $value);
223: if (isset($config->mode)) {
224: foreach($config->mode as $mode =>
$state) {
235: /********************* service factories ****************d*g**/
240: * Get initial instance of service locator.
241: * @return IServiceLocator
247: $locator->addService($service, $name);
255: * @return ICacheStorage