Skip to content

Commit

Permalink
Adjust Kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandoorn committed Oct 1, 2024
1 parent e86e628 commit 2536d91
Showing 1 changed file with 0 additions and 117 deletions.
117 changes: 0 additions & 117 deletions tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,127 +4,10 @@

namespace Tests\SitemapPlugin\Application;

use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel;
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\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Sylius\Calendar\SyliusCalendarBundle;

final 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';
}

public function registerBundles(): iterable
{
foreach ($this->getConfigurationDirectories() as $confDir) {
$bundlesFile = $confDir . '/bundles.php';
if (false === is_file($bundlesFile)) {
continue;
}
yield from $this->registerBundlesFromFile($bundlesFile);

if(class_exists(SyliusCalendarBundle::class)) {
yield new SyliusCalendarBundle();
}
}
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
foreach ($this->getConfigurationDirectories() as $confDir) {
$bundlesFile = $confDir . '/bundles.php';
if (false === is_file($bundlesFile)) {
continue;
}
$container->addResource(new FileResource($bundlesFile));
}

$container->setParameter('container.dumper.inline_class_loader', true);

foreach ($this->getConfigurationDirectories() as $confDir) {
$this->loadContainerConfiguration($loader, $confDir);
}
}

protected function configureRoutes(RouteCollectionBuilder $routes): void
{
foreach ($this->getConfigurationDirectories() as $confDir) {
$this->loadRoutesConfiguration($routes, $confDir);
}
}

protected function getContainerBaseClass(): string
{
if ($this->isTestEnvironment() && class_exists(MockerContainer::class)) {
return MockerContainer::class;
}

return parent::getContainerBaseClass();
}

private function isTestEnvironment(): bool
{
return 0 === strpos($this->getEnvironment(), 'test');
}

private function loadContainerConfiguration(LoaderInterface $loader, string $confDir): void
{
$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');
}

private function loadRoutesConfiguration(RouteCollectionBuilder $routes, string $confDir): void
{
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
}

/**
* @return BundleInterface[]
*/
private function registerBundlesFromFile(string $bundlesFile): iterable
{
$contents = require $bundlesFile;
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}

/**
* @return string[]
*/
private function getConfigurationDirectories(): iterable
{
yield $this->getProjectDir() . '/config';
$syliusConfigDir = $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION;
if (is_dir($syliusConfigDir)) {
yield $syliusConfigDir;
}
$symfonyConfigDir = $this->getProjectDir() . '/config/symfony/' . BaseKernel::MAJOR_VERSION . '.' . BaseKernel::MINOR_VERSION;
if (is_dir($symfonyConfigDir)) {
yield $symfonyConfigDir;
}
}
}

0 comments on commit 2536d91

Please sign in to comment.