Skip to content

Commit 7a2ab8f

Browse files
committed
Add limited Symfony3 support
1 parent 5f7c010 commit 7a2ab8f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Bootstraps/Symfony.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPPM\Symfony\StrongerNativeSessionStorage;
66
use PHPPM\Utils;
77
use Symfony\Component\HttpFoundation\Request;
8+
use Symfony\Component\Dotenv\Dotenv;
89

910
/**
1011
* A default bootstrap for the Symfony framework
@@ -48,11 +49,19 @@ public function getApplication()
4849
require './vendor/autoload.php';
4950
}
5051

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.
5364

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.
5665
Utils::bindAndCall(function() use ($app) {
5766
// init bundles
5867
$app->initializeBundles();
@@ -188,6 +197,19 @@ public function postHandle($app)
188197
$logger->clear();
189198
}
190199
}
200+
}
191201

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+
}
192214
}
193215
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy