Skip to content

Instantly share code, notes, and snippets.

@miedzwin
Last active August 27, 2018 13:47
Show Gist options
  • Save miedzwin/f7ec0e0d51fd88b147037ef189c7960a to your computer and use it in GitHub Desktop.
Save miedzwin/f7ec0e0d51fd88b147037ef189c7960a to your computer and use it in GitHub Desktop.
<?php
/**
* Load environment variables from file and init them
*
* @throws \Exception
*/
private function initEnvironmentVars()
{
$containerBuilder = new ContainerBuilder();
$fileLocator = new FileLocator(__DIR__ . '/../../');
$yamlFileLoader = new YamlFileLoader($containerBuilder, $fileLocator);
try {
$yamlFileLoader->load('.env.yml');
} catch (InvalidArgumentException $e) {
die('Invalid yaml file structure.');
} catch (\Exception $e) {
die('.env.yml file not found. Application cannot start.');
}
$containerBuilder->compile();
$parameterBag = $containerBuilder->getParameterBag();
foreach ($parameterBag->all() as $key => $value) {
putenv("$key=$value");
}
}
<?php
$loader = require __DIR__ . '/../vendor/autoload.php';
// ILFW entry point
use App\Container;
use App\Router;
use Symfony\Component\HttpFoundation\Request;
session_start();
$container = new Container();
$container->init('app');
$container->setParameter('routes', (new Router())->getRouteCollection());
$request = Request::createFromGlobals();
$response = $container->get('framework')->handle($request);
$response->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment