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',
46: 'Nette\Loaders\RobotLoader' =>
array(__CLASS__
, 'createRobotLoader'),
52: * Detect environment mode.
53: * @param string mode name
60: // environment name autodetection
69: // detects production mode by server IP address
70: if (PHP_SAPI ===
'cli') {
73: } elseif (isset($_SERVER['SERVER_ADDR']) ||
isset($_SERVER['LOCAL_ADDR'])) {
74: $addr =
isset($_SERVER['SERVER_ADDR']) ?
$_SERVER['SERVER_ADDR'] :
$_SERVER['LOCAL_ADDR'];
76: // 10.0.0.0/8 Private network
77: // 127.0.0.0/8 Loopback
78: // 169.254.0.0/16 & ::1 Link-Local
79: // 172.16.0.0/12 Private network
80: // 192.168.0.0/16 Private network
81: return $addr !==
'::1' &&
(count($oct) !==
4 ||
($oct[0] !==
'10' &&
$oct[0] !==
'127' &&
($oct[0] !==
'172' ||
$oct[1] <
16 ||
$oct[1] >
31)
82: &&
($oct[0] !==
'169' ||
$oct[1] !==
'254') &&
($oct[0] !==
'192' ||
$oct[1] !==
'168')));
89: return PHP_SAPI ===
'cli';
100: * Loads global configuration from file and process it.
101: * @param string|Nette\Config\Config file name or Config object
113: if ($file ===
NULL) {
120: // process environment variables
122: foreach ($config->variable as $key =>
$value) {
130: $runServices =
array();
133: foreach ($config->service as $key =>
$value) {
134: $key =
strtr($key, '-', '\\'); // limited INI chars
136: $locator->addService($key, $value);
138: if ($value->factory) {
139: $locator->addService($key, $value->factory, isset($value->singleton) ?
$value->singleton :
TRUE, (array)
$value->option);
142: $runServices[] =
$key;
148: // check temporary directory - TODO: discuss
150: $dir = Environment::getVariable('tempDir');
151: if ($dir && !(is_dir($dir) && is_writable($dir))) {
152: trigger_error("Temporary directory '$dir' is not writable", E_USER_NOTICE);
156: // process ini settings
157: if (!$config->php) { // backcompatibility
158: $config->php =
$config->set;
159: unset($config->set);
163: if (PATH_SEPARATOR !==
';' &&
isset($config->php->include_path)) {
164: $config->php->include_path =
str_replace(';', PATH_SEPARATOR, $config->php->include_path);
167: foreach ($config->php as $key =>
$value) { // flatten INI dots
169: unset($config->php->$key);
170: foreach ($value as $k =>
$v) {
171: $config->php->{"$key.$k"} =
$v;
176: foreach ($config->php as $key =>
$value) {
177: $key =
strtr($key, '-', '.'); // backcompatibility
187: case 'include_path':
190: case 'iconv.internal_encoding':
193: case 'mbstring.internal_encoding':
196: case 'date.timezone':
199: case 'error_reporting':
202: case 'ignore_user_abort':
205: case 'max_execution_time':
209: if (ini_get($key) !=
$value) { // intentionally ==
219: foreach ($config->const as $key =>
$value) {
220: define($key, $value);
225: if (isset($config->mode)) {
226: foreach($config->mode as $mode =>
$state) {
231: // auto-start services
232: foreach ($runServices as $name) {
233: $locator->getService($name);
242: /********************* service factories ****************d*g**/
247: * Get initial instance of service locator.
248: * @return IServiceLocator
254: $locator->addService($name, $service);
262: * @return ICacheStorage
272: * @return RobotLoader
278: //$loader->setCache(Environment::getCache('Nette.RobotLoader'));
280: $loader->addDirectory($dirs);
281: $loader->register();