Skip to content

Commit

Permalink
Clean up the test application, use symfony/runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Nov 4, 2023
1 parent 1759424 commit f824da8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 113 deletions.
4 changes: 3 additions & 1 deletion app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"symfony/mailer": "^6.4 || ^7.0",
"symfony/monolog-bundle": "^3.1@dev",
"symfony/rate-limiter": "^6.4 || ^7.0",
"symfony/runtime": "^6.4 || ^7.0",
"symfony/security-bundle": "^6.4 || ^7.0",
"symfony/translation": "^6.4 || ^7.0",
"symfony/twig-bundle": "^6.4 || ^7.0",
Expand All @@ -33,7 +34,8 @@
},
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": false
"composer/package-versions-deprecated": false,
"symfony/runtime": true
}
},
"autoload": {
Expand Down
23 changes: 0 additions & 23 deletions app/config/bootstrap.php

This file was deleted.

4 changes: 0 additions & 4 deletions app/config/preload.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php

if (file_exists(dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php';
}

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}
28 changes: 4 additions & 24 deletions app/public/index.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
<?php

use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\ErrorHandler\DebugClassLoader;
use Symfony\Component\HttpFoundation\Request;

require dirname(__DIR__).'/config/bootstrap.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

Debug::enable();
DebugClassLoader::disable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
61 changes: 0 additions & 61 deletions app/src/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,11 @@
<?php

declare(strict_types=1);

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\Loader\Configurator\RoutingConfigurator;
use function is_dir;

class Kernel extends BaseKernel
{
use MicroKernelTrait;

private const CONFIG_EXTS = '.{php,xml,yaml,yml}';

public function getCacheDir(): string
{
return $this->getProjectDir().'/var/cache/'.$this->environment;
}

public function getLogDir(): string
{
return $this->getProjectDir().'/var/log';
}

/**
* @return iterable<object>
*/
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if (!isset($envs['all']) && !isset($envs[$this->environment])) {
continue;
}

yield new $class();
}
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->setParameter('container.autowiring.strict_mode', true);
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
if (is_dir($confDir.'/packages/'.$this->environment)) {
$loader->load($confDir.'/packages/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
}

$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
}

protected function configureRoutes(RoutingConfigurator $routes): void
{
$confDir = $this->getProjectDir().'/config';
if (is_dir($confDir.'/routes/')) {
$routes->import($confDir.'/routes/*'.self::CONFIG_EXTS);
}

if (is_dir($confDir.'/routes/'.$this->environment)) {
$routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS);
}

$routes->import($confDir.'/routes'.self::CONFIG_EXTS);
}
}

0 comments on commit f824da8

Please sign in to comment.