diff --git a/.gitignore b/.gitignore index 8525dc1291e6c053506f4ee4215919d0b71632ab..29515eda10b880f3f5b617e89fd1e1a58f1b8156 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ ###> symfony/phpunit-bridge ### .phpunit +.phpunit.result.cache /phpunit.xml ###< symfony/phpunit-bridge ### diff --git a/bin/console b/bin/console index 75e8c29dd0b3fab4a707b3534e61e2b6de609cc6..8fe9d4948c71868285c0784e56f10a6ae45d7710 100755 --- a/bin/console +++ b/bin/console @@ -4,14 +4,19 @@ use App\Kernel; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\ErrorHandler\Debug; +if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { + echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; +} + set_time_limit(0); require dirname(__DIR__).'/vendor/autoload.php'; -if (!class_exists(Application::class)) { - throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.'); +if (!class_exists(Application::class) || !class_exists(Dotenv::class)) { + throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.'); } $input = new ArgvInput(); @@ -23,7 +28,7 @@ if ($input->hasParameterOption('--no-debug', true)) { putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); } -require dirname(__DIR__).'/config/bootstrap.php'; +(new Dotenv())->bootEnv(dirname(__DIR__).'/.env'); if ($_SERVER['APP_DEBUG']) { umask(0000); diff --git a/config/bootstrap.php b/config/bootstrap.php deleted file mode 100644 index c6f99d928ec9424cb14e6e485720aa83fd7b40e2..0000000000000000000000000000000000000000 --- a/config/bootstrap.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -declare(strict_types=1); - -use Symfony\Component\Dotenv\Dotenv; - -require dirname(__DIR__).'/vendor/autoload.php'; - -// Load cached env vars if the .env.local.php file exists -// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) -if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { - foreach ($env as $k => $v) { - $_ENV[$k] = $_ENV[$k] ?? (isset($_SERVER[$k]) && 0 !== strpos($k, 'HTTP_') ? $_SERVER[$k] : $v); - } -} elseif (!class_exists(Dotenv::class)) { - throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); -} else { - // load all the .env files - (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env'); -} - -$_SERVER += $_ENV; -$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; -$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; -$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/config/preload.php b/config/preload.php new file mode 100644 index 0000000000000000000000000000000000000000..7cbe578d3ca2477be47b38f5a61e97791679d022 --- /dev/null +++ b/config/preload.php @@ -0,0 +1,7 @@ +<?php + +declare(strict_types=1); + +if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) { + require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php'; +} diff --git a/public/index.php b/public/index.php index 0b568a31a1193b1b1687da9b4e10bb4dbe20a194..52ca8cc7746ed5df6ade3530b603af7dbbb1a795 100644 --- a/public/index.php +++ b/public/index.php @@ -3,31 +3,18 @@ declare(strict_types=1); use App\Kernel; +use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\ErrorHandler\Debug; use Symfony\Component\HttpFoundation\Request; -// FPM renames all environment variables! -if (isset($_SERVER['REDIRECT_APP_ENV'])) { - $_SERVER['APP_ENV'] = $_SERVER['REDIRECT_APP_ENV']; -} +require dirname(__DIR__).'/vendor/autoload.php'; -require dirname(__DIR__).'/config/bootstrap.php'; +(new Dotenv())->bootEnv(dirname(__DIR__).'/.env'); if ($_SERVER['APP_DEBUG']) { umask(0000); Debug::enable(); -} else { - // Set a dummy dumper handler to avoid left over dump() commands breaking production - \Symfony\Component\VarDumper\VarDumper::setHandler(function ($var) {}); -} - -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']); diff --git a/src/Kernel.php b/src/Kernel.php index b94a45f9d9e1fec921cd5d87777dbbc377f20263..e63175f553a2f72525ed114d52cd998d04ef0ffd 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -5,46 +5,36 @@ declare(strict_types=1); namespace App; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\HttpKernel\Kernel as BaseKernel; -use Symfony\Component\Routing\RouteCollectionBuilder; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; class Kernel extends BaseKernel { use MicroKernelTrait; - private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; - - public function registerBundles(): iterable + protected function configureContainer(ContainerConfigurator $container): void { - $contents = require $this->getProjectDir().'/config/bundles.php'; - foreach ($contents as $class => $envs) { - if ($envs[$this->environment] ?? $envs['all'] ?? false) { - yield new $class(); - } + $container->import('../config/{packages}/*.yaml'); + $container->import('../config/{packages}/'.$this->environment.'/*.yaml'); + + if (is_file(\dirname(__DIR__).'/config/services.yaml')) { + $container->import('../config/services.yaml'); + $container->import('../config/{services}_'.$this->environment.'.yaml'); + } elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) { + (require $path)($container->withPath($path), $this); } } - protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void + protected function configureRoutes(RoutingConfigurator $routes): void { - $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); - $container->setParameter('container.dumper.inline_class_loader', true); - $confDir = $this->getProjectDir().'/config'; - - $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob'); - $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'); - } + $routes->import('../config/{routes}/'.$this->environment.'/*.yaml'); + $routes->import('../config/{routes}/*.yaml'); - protected function configureRoutes(RouteCollectionBuilder $routes): void - { - $confDir = $this->getProjectDir().'/config'; - - $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); - $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); - $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); + if (is_file(\dirname(__DIR__).'/config/routes.yaml')) { + $routes->import('../config/routes.yaml'); + } elseif (is_file($path = \dirname(__DIR__).'/config/routes.php')) { + (require $path)($routes->withPath($path), $this); + } } } diff --git a/symfony.lock b/symfony.lock index c39a5be95bb44518eabf927e75c4fa16c90525f0..9e270964ca3c86f580bb77eaddf14fbe7ad63385 100644 --- a/symfony.lock +++ b/symfony.lock @@ -227,16 +227,15 @@ "version": "v4.4.16" }, "symfony/console": { - "version": "4.4", + "version": "5.1", "recipe": { "repo": "github.com/symfony/recipes", "branch": "master", - "version": "4.4", - "ref": "ea8c0eda34fda57e7d5cd8cbd889e2a387e3472c" + "version": "5.1", + "ref": "c6d02bdfba9da13c22157520e32a602dbee8a75c" }, "files": [ - "bin/console", - "config/bootstrap.php" + "bin/console" ] }, "symfony/contracts": { @@ -300,15 +299,14 @@ ] }, "symfony/framework-bundle": { - "version": "4.4", + "version": "5.2", "recipe": { "repo": "github.com/symfony/recipes", "branch": "master", - "version": "4.4", - "ref": "2257d2a1754c7840f49ad04e1d529c402415f4b5" + "version": "5.2", + "ref": "6ec87563dcc85cd0c48856dcfbfc29610506d250" }, "files": [ - "config/bootstrap.php", "config/packages/cache.yaml", "config/packages/framework.yaml", "config/packages/test/framework.yaml", @@ -360,12 +358,12 @@ "version": "v4.4.16" }, "symfony/phpunit-bridge": { - "version": "4.3", + "version": "5.1", "recipe": { "repo": "github.com/symfony/recipes", "branch": "master", - "version": "4.3", - "ref": "6d0e35f749d5f4bfe1f011762875275cd3f9874f" + "version": "5.1", + "ref": "bf16921ef8309a81d9f046e9b6369c46bcbd031f" }, "files": [ ".env.test",