Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Callback
  • Configurator
  • Environment
  • Framework
  • FreezableObject
  • Object

Interfaces

  • IFreezable

Traits

  • SmartObject
  • StaticClass

Exceptions

  • ArgumentOutOfRangeException
  • DeprecatedException
  • DirectoryNotFoundException
  • FileNotFoundException
  • InvalidArgumentException
  • InvalidStateException
  • IOException
  • MemberAccessException
  • NotImplementedException
  • NotSupportedException
  • OutOfRangeException
  • StaticClassException
  • UnexpectedValueException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Nette environment and configuration.
 15:  * @deprecated
 16:  */
 17: class Environment
 18: {
 19:     /** environment name */
 20:     const DEVELOPMENT = 'development',
 21:         PRODUCTION = 'production',
 22:         CONSOLE = 'console';
 23: 
 24:     /** @var bool */
 25:     private static $productionMode;
 26: 
 27:     /** @var string */
 28:     private static $createdAt;
 29: 
 30:     /** @var Nette\DI\Container */
 31:     private static $context;
 32: 
 33: 
 34:     /**
 35:      * Static class - cannot be instantiated.
 36:      */
 37:     final public function __construct()
 38:     {
 39:         throw new StaticClassException;
 40:     }
 41: 
 42: 
 43:     /********************* environment modes ****************d*g**/
 44: 
 45: 
 46:     /**
 47:      * Detects console (non-HTTP) mode.
 48:      * @return bool
 49:      */
 50:     public static function isConsole()
 51:     {
 52:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
 53:         return PHP_SAPI === 'cli';
 54:     }
 55: 
 56: 
 57:     /**
 58:      * Determines whether a server is running in production mode.
 59:      * @return bool
 60:      */
 61:     public static function isProduction()
 62:     {
 63:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
 64:         if (self::$productionMode === NULL) {
 65:             self::$productionMode = !Nette\Configurator::detectDebugMode();
 66:         }
 67:         return self::$productionMode;
 68:     }
 69: 
 70: 
 71:     /**
 72:      * Enables or disables production mode.
 73:      * @param  bool
 74:      * @return void
 75:      */
 76:     public static function setProductionMode($value = TRUE)
 77:     {
 78:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
 79:         self::$productionMode = (bool) $value;
 80:     }
 81: 
 82: 
 83:     /********************* environment variables ****************d*g**/
 84: 
 85: 
 86:     /**
 87:      * Sets the environment variable.
 88:      * @param  string
 89:      * @param  mixed
 90:      * @param  bool
 91:      * @return void
 92:      */
 93:     public static function setVariable($name, $value, $expand = TRUE)
 94:     {
 95:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
 96:         if ($expand && is_string($value)) {
 97:             $value = self::getContext()->expand($value);
 98:         }
 99:         self::getContext()->parameters[$name] = $value;
100:     }
101: 
102: 
103:     /**
104:      * Returns the value of an environment variable or $default if there is no element set.
105:      * @param  string
106:      * @param  mixed  default value to use if key not found
107:      * @return mixed
108:      * @throws InvalidStateException
109:      */
110:     public static function getVariable($name, $default = NULL)
111:     {
112:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
113:         if (isset(self::getContext()->parameters[$name])) {
114:             return self::getContext()->parameters[$name];
115:         } elseif (func_num_args() > 1) {
116:             return $default;
117:         } else {
118:             throw new InvalidStateException("Unknown environment variable '$name'.");
119:         }
120:     }
121: 
122: 
123:     /**
124:      * Returns the all environment variables.
125:      * @return array
126:      */
127:     public static function getVariables()
128:     {
129:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
130:         return self::getContext()->parameters;
131:     }
132: 
133: 
134:     /**
135:      * Returns expanded variable.
136:      * @param  string
137:      * @return string
138:      * @throws InvalidStateException
139:      */
140:     public static function expand($s)
141:     {
142:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
143:         return self::getContext()->expand($s);
144:     }
145: 
146: 
147:     /********************* context ****************d*g**/
148: 
149: 
150:     /**
151:      * Sets initial instance of context.
152:      * @return void
153:      */
154:     public static function setContext(DI\Container $context)
155:     {
156:         if (self::$createdAt) {
157:             throw new Nette\InvalidStateException('Configurator & SystemContainer has already been created automatically by Nette\Environment at ' . self::$createdAt);
158:         }
159:         self::$context = $context;
160:     }
161: 
162: 
163:     /**
164:      * Get initial instance of context.
165:      * @return Nette\DI\Container
166:      */
167:     public static function getContext()
168:     {
169:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
170:         if (self::$context === NULL) {
171:             self::loadConfig();
172:         }
173:         return self::$context;
174:     }
175: 
176: 
177:     /**
178:      * Gets the service object of the specified type.
179:      * @param  string service name
180:      * @return object
181:      */
182:     public static function getService($name)
183:     {
184:         return self::getContext()->getService($name);
185:     }
186: 
187: 
188:     /**
189:      * Calling to undefined static method.
190:      * @param  string  method name
191:      * @param  array   arguments
192:      * @return object  service
193:      */
194:     public static function __callStatic($name, $args)
195:     {
196:         if (!$args && strncasecmp($name, 'get', 3) === 0) {
197:             return self::getService(lcfirst(substr($name, 3)));
198:         } else {
199:             throw new MemberAccessException("Call to undefined static method Nette\\Environment::$name().");
200:         }
201:     }
202: 
203: 
204:     /**
205:      * @return Nette\Http\Request
206:      */
207:     public static function getHttpRequest()
208:     {
209:         return self::getContext()->getByType('Nette\Http\IRequest');
210:     }
211: 
212: 
213:     /**
214:      * @return Nette\Http\Context
215:      */
216:     public static function getHttpContext()
217:     {
218:         return self::getContext()->getByType('Nette\Http\Context');
219:     }
220: 
221: 
222:     /**
223:      * @return Nette\Http\Response
224:      */
225:     public static function getHttpResponse()
226:     {
227:         return self::getContext()->getByType('Nette\Http\IResponse');
228:     }
229: 
230: 
231:     /**
232:      * @return Nette\Application\Application
233:      */
234:     public static function getApplication()
235:     {
236:         return self::getContext()->getByType('Nette\Application\Application');
237:     }
238: 
239: 
240:     /**
241:      * @return Nette\Security\User
242:      */
243:     public static function getUser()
244:     {
245:         return self::getContext()->getByType('Nette\Security\User');
246:     }
247: 
248: 
249:     /**
250:      * @return Nette\Loaders\RobotLoader
251:      */
252:     public static function getRobotLoader()
253:     {
254:         return self::getContext()->getByType('Nette\Loaders\RobotLoader');
255:     }
256: 
257: 
258:     /********************* service factories ****************d*g**/
259: 
260: 
261:     /**
262:      * @param  string
263:      * @return Nette\Caching\Cache
264:      */
265:     public static function getCache($namespace = '')
266:     {
267:         return new Caching\Cache(self::getContext()->getByType('Nette\Caching\IStorage'), $namespace);
268:     }
269: 
270: 
271:     /**
272:      * Returns instance of session or session namespace.
273:      * @param  string
274:      * @return Nette\Http\Session
275:      */
276:     public static function getSession($namespace = NULL)
277:     {
278:         return $namespace === NULL
279:             ? self::getContext()->getByType('Nette\Http\Session')
280:             : self::getContext()->getByType('Nette\Http\Session')->getSection($namespace);
281:     }
282: 
283: 
284:     /********************* global configuration ****************d*g**/
285: 
286: 
287:     /**
288:      * Loads global configuration from file and process it.
289:      * @param  string
290:      * @param  string
291:      * @return Nette\Utils\ArrayHash
292:      */
293:     public static function loadConfig($file = NULL, $section = NULL)
294:     {
295:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
296:         if (self::$createdAt) {
297:             throw new Nette\InvalidStateException('Nette\Configurator has already been created automatically by Nette\Environment at ' . self::$createdAt);
298:         } elseif (!defined('TEMP_DIR')) {
299:             throw new Nette\InvalidStateException('Nette\Environment requires constant TEMP_DIR with path to temporary directory.');
300:         }
301:         $configurator = new Nette\Configurator;
302:         $configurator
303:             ->setDebugMode(!self::isProduction())
304:             ->setTempDirectory(TEMP_DIR)
305:             ->addParameters(array('container' => array('class' => 'EnvironmentContainer')));
306:         if ($file) {
307:             $configurator->addConfig($file, $section);
308:         }
309:         self::$context = $configurator->createContainer();
310: 
311:         self::$createdAt = '?';
312:         foreach (debug_backtrace(FALSE) as $row) {
313:             if (isset($row['file']) && $row['file'] !== __FILE__ && is_file($row['file'])) {
314:                 self::$createdAt = "$row[file]:$row[line]";
315:                 break;
316:             }
317:         }
318:         return self::getConfig();
319:     }
320: 
321: 
322:     /**
323:      * Returns the global configuration.
324:      * @param  string key
325:      * @param  mixed  default value
326:      * @return mixed
327:      */
328:     public static function getConfig($key = NULL, $default = NULL)
329:     {
330:         trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
331:         $params = Nette\Utils\ArrayHash::from(self::getContext()->parameters);
332:         if (func_num_args()) {
333:             return isset($params[$key]) ? $params[$key] : $default;
334:         } else {
335:             return $params;
336:         }
337:     }
338: 
339: }
340: 
Nette 2.4-20170119 API API documentation generated by ApiGen 2.8.0