added simpler and easier environment handling.

This commit is contained in:
Taylor Otwell
2012-04-12 23:35:41 -05:00
parent 34cb9a00f4
commit ab6e364546
4 changed files with 123 additions and 61 deletions

View File

@@ -208,6 +208,31 @@ class Request {
return static::env() === $env;
}
/**
* Detect the current environment from an environment configuration.
*
* @param array $environments
* @return string|null
*/
public static function detect_env(array $environments)
{
$root = static::foundation()->getRootUrl();
foreach ($environments as $environment => $patterns)
{
// Essentially we just want to loop through each environment pattern
// and determine if the current URI matches the pattern and if so
// we'll simply return the environment for that URI pattern.
foreach ($patterns as $pattern)
{
if (Str::is($pattern, $root))
{
return $environment;
}
}
}
}
/**
* Get the main route handling the request.
*