added Kernel

This commit is contained in:
Fabien Potencier
2017-03-09 16:26:48 -08:00
parent 4d56dc57ce
commit d6bce75ab5
4 changed files with 73 additions and 2 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php
use App\Kernel;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Bundle\FrameworkBundle\Console\Application;
@@ -33,6 +34,6 @@ if ($debug && class_exists(Debug::class)) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$kernel = new Kernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
@@ -4,6 +4,7 @@
},
"copy-from-recipe": {
"etc/": "%ETC_DIR%/",
"src/": "%SRC_DIR%/",
"web/": "%WEB_DIR%/"
},
"composer-scripts": {
@@ -0,0 +1,68 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class Kernel extends BaseKernel
{
use MicroKernelTrait;
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function getCacheDir()
{
return dirname(dirname(__DIR__)).'/var/cache/'.$this->environment;
}
public function getLogDir()
{
return dirname(dirname(__DIR__)).'/var/logs';
}
public function registerBundles()
{
$contents = require dirname($this->getRootDir()).'/etc/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->getEnvironment()])) {
yield new $class();
}
}
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
$confDir = dirname($this->getRootDir()).'/etc';
$loader->import($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
if (is_dir($confDir.'/packages/'.$this->getEnvironment())) {
$loader->import($confDir.'/packages/'.$this->getEnvironment().'/**/*'.self::CONFIG_EXTS, 'glob');
}
$loader->import($confDir.'/container'.self::CONFIG_EXTS, 'glob');
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$confDir = dirname($this->getRootDir()).'/etc';
$routes->import($confDir.'/routing/*'.self::CONFIG_EXTS, '/', 'glob');
if (is_dir($confDir.'/routing/'.$this->getEnvironment())) {
$routes->import($confDir.'/routing/'.$this->getEnvironment().'/**/*'.self::CONFIG_EXTS, '/', 'glob');
}
$routes->import($confDir.'/routing'.self::CONFIG_EXTS, '/', 'glob');
}
}
@@ -1,5 +1,6 @@
<?php
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
@@ -39,7 +40,7 @@ if (getenv('APP_DEBUG')) {
// Request::setTrustedProxiestTrustedHeaderName(Request::HEADER_FORWARDED, null);
// Request::setTrustedProxies(['0.0.0.0/0']);
$kernel = new AppKernel(getenv('APP_ENV'), getenv('APP_DEBUG'));
$kernel = new Kernel(getenv('APP_ENV'), getenv('APP_DEBUG'));
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();