|
5 | 5 | use PHPPM\Symfony\StrongerNativeSessionStorage;
|
6 | 6 | use PHPPM\Utils;
|
7 | 7 | use Symfony\Component\HttpFoundation\Request;
|
| 8 | +use Symfony\Component\Dotenv\Dotenv; |
8 | 9 |
|
9 | 10 | /**
|
10 | 11 | * A default bootstrap for the Symfony framework
|
@@ -48,11 +49,19 @@ public function getApplication()
|
48 | 49 | require './vendor/autoload.php';
|
49 | 50 | }
|
50 | 51 |
|
51 |
| - //since we need to change some services, we need to manually change some services |
52 |
| - $app = new \AppKernel($this->appenv, $this->debug); |
| 52 | + // since we need to change some services, we need to manually change some services |
| 53 | + $class = class_exists('\AppKernel') ? '\AppKernel' : '\App\Kernel'; |
| 54 | + $app = new $class($this->appenv, $this->debug); |
| 55 | + |
| 56 | + // environment loading as of Symfony 3.3 |
| 57 | + if (class_exists('\Symfony\Component\Dotenv\Dotenv')) { |
| 58 | + $this->loadEnvironment('.env'); |
| 59 | + } |
| 60 | + |
| 61 | + // We need to change some services, before the boot, because they would |
| 62 | + // otherwise be instantiated and passed to other classes which makes it |
| 63 | + // impossible to replace them. |
53 | 64 |
|
54 |
| - //we need to change some services, before the boot, because they would otherwise |
55 |
| - //be instantiated and passed to other classes which makes it impossible to replace them. |
56 | 65 | Utils::bindAndCall(function() use ($app) {
|
57 | 66 | // init bundles
|
58 | 67 | $app->initializeBundles();
|
@@ -188,6 +197,19 @@ public function postHandle($app)
|
188 | 197 | $logger->clear();
|
189 | 198 | }
|
190 | 199 | }
|
| 200 | + } |
191 | 201 |
|
| 202 | + /** |
| 203 | + * Load environment variables from .env file |
| 204 | + * @param string $env the enviroment file |
| 205 | + */ |
| 206 | + protected function loadEnvironment($env) |
| 207 | + { |
| 208 | + // if Symfony is at root folder |
| 209 | + $path = __DIR__ . '/../../../../' . $env; |
| 210 | + |
| 211 | + if (file_exists($path)) { |
| 212 | + (new Dotenv())->load($path); |
| 213 | + } |
192 | 214 | }
|
193 | 215 | }
|
0 commit comments