lithium\core\Environment::_detector()

protected static method

Accessor method for Environment::$_detector. If $_detector is unset, returns the default detector built into the class. For more information on setting and using $_detector, see the documentation for Environment::is(). The _detector() method is called at the beginning of the application's life-cycle, when Environment::set() is passed either an instance of a Request object, or the $_SERVER or $_ENV array. This object (or array) is then passed onto $_detector, which returns the correct environment.

Returns

object

Returns a callable object (anonymous function) which detects the application's current environment.

Source

	protected static function _detector() {
		return static::$_detector ?: function($request) {
			$isLocal = in_array($request->env('SERVER_ADDR'), ['::1', '127.0.0.1']);
			switch (true) {
				case (isset($request->env)):
					return $request->env;
				case ($request->command == 'test'):
					return 'test';
				case ($request->env('PLATFORM') == 'CLI'):
					return 'development';
				case (preg_match('/^\/test/', $request->url) && $isLocal):
					return 'test';
				case ($isLocal):
					return 'development';
				case (preg_match('/^test/', $request->env('HTTP_HOST'))):
					return 'test';
				default:
					return 'production';
			}
		};
	}