Skip to content

Commit

Permalink
Add limited Symfony3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Oct 24, 2017
1 parent 5f7c010 commit 7a2ab8f
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Bootstraps/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPPM\Symfony\StrongerNativeSessionStorage;
use PHPPM\Utils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Dotenv\Dotenv;

/**
* A default bootstrap for the Symfony framework
Expand Down Expand Up @@ -48,11 +49,19 @@ public function getApplication()
require './vendor/autoload.php';
}

//since we need to change some services, we need to manually change some services
$app = new \AppKernel($this->appenv, $this->debug);
// since we need to change some services, we need to manually change some services
$class = class_exists('\AppKernel') ? '\AppKernel' : '\App\Kernel';
$app = new $class($this->appenv, $this->debug);

// environment loading as of Symfony 3.3
if (class_exists('\Symfony\Component\Dotenv\Dotenv')) {
$this->loadEnvironment('.env');
}

// We need to change some services, before the boot, because they would
// otherwise be instantiated and passed to other classes which makes it
// impossible to replace them.

//we need to change some services, before the boot, because they would otherwise
//be instantiated and passed to other classes which makes it impossible to replace them.
Utils::bindAndCall(function() use ($app) {
// init bundles
$app->initializeBundles();
Expand Down Expand Up @@ -188,6 +197,19 @@ public function postHandle($app)
$logger->clear();
}
}
}

/**
* Load environment variables from .env file
* @param string $env the enviroment file
*/
protected function loadEnvironment($env)
{
// if Symfony is at root folder
$path = __DIR__ . '/../../../../' . $env;

if (file_exists($path)) {
(new Dotenv())->load($path);
}
}
}

0 comments on commit 7a2ab8f

Please sign in to comment.