Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8aaf23b

Browse files
committed
Merge branch '4.1'
2 parents 85f972a + 06bfa77 commit 8aaf23b

6 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php namespace Illuminate\Config;
2+
3+
/**
4+
* PHP $_ENV loader for protecting sensitive configuration options.
5+
*
6+
* Inspired by the wonderful "Dotenv" library by Vance Lucas.
7+
*/
8+
class EnvironmentVariables {
9+
10+
/**
11+
* The environment loader implementation.
12+
*
13+
* @var \Illuminate\Config\EnvironmentLoaderInterface $loader
14+
*/
15+
protected $loader;
16+
17+
/**
18+
* The server environment instance.
19+
*
20+
* @param \Illuminate\Config\EnvironmentLoaderInterface $loader
21+
* @return void
22+
*/
23+
public function __construct(EnvironmentVariablesLoaderInterface $loader)
24+
{
25+
$this->loader = $loader;
26+
}
27+
28+
/**
29+
* Load the server variables for a given environment.
30+
*
31+
* @param string $environment
32+
*/
33+
public function load($environment = null)
34+
{
35+
foreach ($this->loader->load($environment) as $key => $value)
36+
{
37+
$_ENV[$key] = $value;
38+
39+
$_SERVER[$key] = $value;
40+
}
41+
}
42+
43+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php namespace Illuminate\Config;
2+
3+
interface EnvironmentVariablesLoaderInterface {
4+
5+
/**
6+
* Load the environment variables for the given environment.
7+
*
8+
* @param string $environment
9+
* @return array
10+
*/
11+
public function load($environment = null);
12+
13+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php namespace Illuminate\Config;
2+
3+
use Illuminate\Filesystem\Filesystem;
4+
5+
class FileEnvironmentVariablesLoader implements EnvironmentVariablesLoaderInterface {
6+
7+
/**
8+
* The filesystem instance.
9+
*
10+
* @var \Illuminate\Filesystem\Filesystem
11+
*/
12+
protected $files;
13+
14+
/**
15+
* The path to the configuration files.
16+
*
17+
* @var string
18+
*/
19+
protected $path;
20+
21+
/**
22+
* Create a new file environment loader instance.
23+
*
24+
* @param \Illumiante\Filesystem\Filesystem $files
25+
* @return void
26+
*/
27+
public function __construct(Filesystem $files, $path = null)
28+
{
29+
$this->files = $files;
30+
$this->path = $path ?: base_path();
31+
}
32+
33+
/**
34+
* Load the environment variables for the given environment.
35+
*
36+
* @param string $environment
37+
* @return array
38+
*/
39+
public function load($environment = null)
40+
{
41+
if ($environment == 'production') $environment = null;
42+
43+
if ( ! $this->files->exists($path = $this->getFile($environment)))
44+
{
45+
return array();
46+
}
47+
else
48+
{
49+
return $this->files->getRequire($path);
50+
}
51+
}
52+
53+
/**
54+
* Get the file for the given environment.
55+
*
56+
* @param string $environment
57+
* @return string
58+
*/
59+
protected function getFile($environment)
60+
{
61+
if ($environment)
62+
{
63+
return $this->path.'/.env.'.$environment.'.php';
64+
}
65+
else
66+
{
67+
return $this->path.'/.env.php';
68+
}
69+
}
70+
71+
}

src/Illuminate/Foundation/Application.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Events\EventServiceProvider;
1111
use Illuminate\Routing\RoutingServiceProvider;
1212
use Illuminate\Exception\ExceptionServiceProvider;
13+
use Illuminate\Config\FileEnvironmentVariablesLoader;
1314
use Symfony\Component\HttpKernel\HttpKernelInterface;
1415
use Symfony\Component\HttpKernel\TerminableInterface;
1516
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -914,6 +915,16 @@ public function getConfigLoader()
914915
return new FileLoader(new Filesystem, $this['path'].'/config');
915916
}
916917

918+
/**
919+
* Get the environment variables loader instance.
920+
*
921+
* @return \Illuminate\Config\EnvironmentVariablesLoaderInterface
922+
*/
923+
public function getEnvironmentVariablesLoader()
924+
{
925+
return new FileEnvironmentVariablesLoader(new Filesystem, $this['path.base']);
926+
}
927+
917928
/**
918929
* Get the service provider repository instance.
919930
*

src/Illuminate/Foundation/Console/Optimize/config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/NamespacedItemResolver.php',
3838
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/FileLoader.php',
3939
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/LoaderInterface.php',
40+
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/EnvironmentVariablesLoaderInterface.php',
41+
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/FileEnvironmentVariablesLoader.php',
42+
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/EnvironmentVariables.php',
4043
$basePath.'/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php',
4144
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php',
4245
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php',

src/Illuminate/Foundation/start.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use Illuminate\Http\Request;
4646
use Illuminate\Support\Facades\Facade;
4747
use Illuminate\Foundation\AliasLoader;
48+
use Illuminate\Config\EnvironmentVariables;
4849
use Illuminate\Config\Repository as Config;
4950

5051
/*
@@ -104,6 +105,20 @@
104105

105106
$app->registerCoreContainerAliases();
106107

108+
/*
109+
|--------------------------------------------------------------------------
110+
| Register The Environment Variables
111+
|--------------------------------------------------------------------------
112+
|
113+
| Here we will register all of the $_ENV and $_SERVER variables into the
114+
| process so that they're globally available configuration options so
115+
| sensitive configuration information can be swept out of the code.
116+
|
117+
*/
118+
119+
with($envVariables = new EnvironmentVariables(
120+
$app->getEnvironmentVariablesLoader()))->load($env);
121+
107122
/*
108123
|--------------------------------------------------------------------------
109124
| Register The Configuration Repository

0 commit comments

Comments
 (0)