added simpler and easier environment handling.
This commit is contained in:
parent
34cb9a00f4
commit
ab6e364546
145
laravel/core.php
145
laravel/core.php
|
@ -106,63 +106,6 @@
|
||||||
=> path('sys').'vendor/Symfony/Component/HttpFoundation',
|
=> path('sys').'vendor/Symfony/Component/HttpFoundation',
|
||||||
));
|
));
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Set The CLI Options Array
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| If the current request is from the Artisan command-line interface, we
|
|
||||||
| will parse the command line arguments and options and set them the
|
|
||||||
| array of options in the $_SERVER global array for convenience.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (defined('STDIN'))
|
|
||||||
{
|
|
||||||
$console = CLI\Command::options($_SERVER['argv']);
|
|
||||||
|
|
||||||
list($arguments, $options) = $console;
|
|
||||||
|
|
||||||
$options = array_change_key_case($options, CASE_UPPER);
|
|
||||||
|
|
||||||
$_SERVER['CLI'] = $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Set The CLI Laravel Environment
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Next we'll set the LARAVEL_ENV variable if the current request is from
|
|
||||||
| the Artisan command-line interface. Since the environment is often
|
|
||||||
| specified within an Apache .htaccess file, we need to set it here
|
|
||||||
| when the request is not coming through Apache.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (isset($_SERVER['CLI']['ENV']))
|
|
||||||
{
|
|
||||||
$_SERVER['LARAVEL_ENV'] = $_SERVER['CLI']['ENV'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Register The Laravel Bundles
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Finally we will register all of the bundles that have been defined for
|
|
||||||
| the application. None of them will be started, yet but will be setup
|
|
||||||
| so that they may be started by the develop at any time.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
$bundles = require path('app').'bundles'.EXT;
|
|
||||||
|
|
||||||
foreach ($bundles as $bundle => $config)
|
|
||||||
{
|
|
||||||
Bundle::register($bundle, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Magic Quotes Strip Slashes
|
| Magic Quotes Strip Slashes
|
||||||
|
@ -197,4 +140,90 @@
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
|
use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
|
||||||
|
|
||||||
Request::$foundation = RequestFoundation::createFromGlobals();
|
Request::$foundation = RequestFoundation::createFromGlobals();
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Determine The Application Environment
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Next we're ready to determine the application environment. This may be
|
||||||
|
| set either via the command line options, or, if the request is from
|
||||||
|
| the web, via the mapping of URIs to environments that lives in
|
||||||
|
| the "paths.php" file for the application and is parsed.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (Request::cli())
|
||||||
|
{
|
||||||
|
foreach (Request::foundation()->server->get('argv') as $argument)
|
||||||
|
{
|
||||||
|
if (starts_with($argument, '--env='))
|
||||||
|
{
|
||||||
|
$environment = substr($argument, 6);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$environment = Request::detect_env($environments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Set The Application Environment
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Once we have determined the application environment, we will set it on
|
||||||
|
| the global server array of the HttpFoundation request. This makes it
|
||||||
|
| available throughout the application, thought it is mainly only
|
||||||
|
| used to determine which configuration files to merge in.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! is_null($environment))
|
||||||
|
{
|
||||||
|
Request::foundation()->server->set('LARAVEL_ENV', $environment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Set The CLI Options Array
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| If the current request is from the Artisan command-line interface, we
|
||||||
|
| will parse the command line arguments and options and set them the
|
||||||
|
| array of options in the $_SERVER global array for convenience.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (defined('STDIN'))
|
||||||
|
{
|
||||||
|
$console = CLI\Command::options($_SERVER['argv']);
|
||||||
|
|
||||||
|
list($arguments, $options) = $console;
|
||||||
|
|
||||||
|
$options = array_change_key_case($options, CASE_UPPER);
|
||||||
|
|
||||||
|
$_SERVER['CLI'] = $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register The Laravel Bundles
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Finally we will register all of the bundles that have been defined for
|
||||||
|
| the application. None of them will be started, yet but will be setup
|
||||||
|
| so that they may be started by the develop at any time.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$bundles = require path('app').'bundles'.EXT;
|
||||||
|
|
||||||
|
foreach ($bundles as $bundle => $config)
|
||||||
|
{
|
||||||
|
Bundle::register($bundle, $config);
|
||||||
|
}
|
|
@ -208,6 +208,31 @@ public static function is_env($env)
|
||||||
return static::env() === $env;
|
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.
|
* Get the main route handling the request.
|
||||||
*
|
*
|
||||||
|
|
|
@ -70,9 +70,7 @@ public static function base()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$f = Request::foundation();
|
$base = Request::foundation()->getRootUrl();
|
||||||
|
|
||||||
$base = $f->getScheme().'://'.$f->getHttpHost().$f->getBasePath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::$base = $base;
|
return static::$base = $base;
|
||||||
|
|
|
@ -24,4 +24,14 @@ static public function createFromGlobals()
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the root URL of the application.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRootUrl()
|
||||||
|
{
|
||||||
|
return $this->getScheme().'://'.$this->getHttpHost().$this->getBasePath();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue