Skip to content

Commit 2d5ec88

Browse files
committed
Refactor before fixing CI
1 parent 72c5008 commit 2d5ec88

File tree

4 files changed

+49
-65
lines changed

4 files changed

+49
-65
lines changed

features/bootstrap/AbstractContext.php

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use DemoApp\DefaultKernel;
77
use Symfony\Component\HttpFoundation\Request;
88
use Symfony\Component\HttpFoundation\Response;
9+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
910

1011
class AbstractContext implements Context
1112
{
@@ -23,6 +24,15 @@ public function jsonDecode($encodedData)
2324
return $decoded;
2425
}
2526

27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function configureRoutes(RoutingConfigurator $routes)
31+
{
32+
$confDir = $this->getConfigDir();
33+
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, 'glob');
34+
}
35+
2636
/**
2737
* @param string $uri
2838
* @param string $httpMethod

features/demo_app/src/AbstractKernel.php

+29-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
namespace DemoApp;
33

44
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
5+
use Symfony\Component\Config\Loader\LoaderInterface;
56
use Symfony\Component\DependencyInjection\Container;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
68
use Symfony\Component\HttpKernel\Kernel as BaseHttpKernel;
79

810
abstract class AbstractKernel extends BaseHttpKernel
@@ -13,14 +15,26 @@ abstract class AbstractKernel extends BaseHttpKernel
1315
/** @var string|null */
1416
private $customCacheDir = null;
1517

18+
public function registerBundles(): iterable
19+
{
20+
/** @noinspection PhpIncludeInspection */
21+
$contents = require $this->getConfigDir().'/bundles.php';
22+
foreach ($contents as $class => $envs) {
23+
if (isset($envs['all']) || isset($envs[$this->environment])) {
24+
yield new $class();
25+
}
26+
}
27+
}
28+
29+
1630
/**
1731
* {@inheritdoc}
1832
*/
1933
public function getCacheDir()
2034
{
2135
// Use a specific cache for each kernels
2236
if (null === $this->customCacheDir) {
23-
$this->customCacheDir = $this->getProjectDir().'/var/cache/'.$this->environment.'/'.$this->getConfigDirectory();
37+
$this->customCacheDir = $this->getProjectDir().'/var/cache/'.$this->environment.'/'.$this->getConfigDirectoryName();
2438
}
2539

2640
return $this->customCacheDir;
@@ -41,6 +55,17 @@ public function getProjectDir()
4155
{
4256
return realpath(__DIR__.'/../');
4357
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
63+
{
64+
$container->setParameter('container.dumper.inline_class_loader', true);
65+
$confDir = $this->getConfigDir();
66+
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
67+
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
68+
}
4469

4570
/**
4671
* Gets the container class.
@@ -50,8 +75,9 @@ public function getProjectDir()
5075
protected function getContainerClass()
5176
{
5277
// In order to avoid collisions between kernels use a dedicated name
53-
return parent::getContainerClass().Container::camelize($this->getConfigDirectory());
78+
return parent::getContainerClass().Container::camelize($this->getConfigDirectoryName());
5479
}
5580

56-
abstract public function getConfigDirectory() : string;
81+
abstract public function getConfigDirectoryName() : string;
82+
abstract public function getConfigDir(): string;
5783
}

features/demo_app/src/DefaultKernel.php

+5-31
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,20 @@
33

44
use Symfony\Component\Config\Loader\LoaderInterface;
55
use Symfony\Component\DependencyInjection\ContainerBuilder;
6-
use Symfony\Component\Routing\RouteCollectionBuilder;
6+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
77

88
class DefaultKernel extends AbstractKernel
99
{
10-
public function registerBundles(): iterable
11-
{
12-
/** @noinspection PhpIncludeInspection */
13-
$contents = require $this->getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php';
14-
foreach ($contents as $class => $envs) {
15-
if (isset($envs['all']) || isset($envs[$this->environment])) {
16-
yield new $class();
17-
}
18-
}
19-
}
20-
21-
/**
22-
* {@inheritdoc}
23-
*/
24-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
25-
{
26-
$container->setParameter('container.dumper.inline_class_loader', true);
27-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
28-
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
29-
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
30-
}
31-
3210
/**
3311
* {@inheritdoc}
3412
*/
35-
protected function configureRoutes(RouteCollectionBuilder $routes)
13+
public function getConfigDirectoryName() : string
3614
{
37-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
38-
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
15+
return 'default_config';
3916
}
4017

41-
/**
42-
* {@inheritdoc}
43-
*/
44-
public function getConfigDirectory() : string
18+
public function getConfigDir(): string
4519
{
46-
return 'default_config';
20+
return $this->getProjectDir().'/'.$this->getConfigDirectoryName();
4721
}
4822
}

features/demo_app/src/KernelWithMappingCollectorListener.php

+5-31
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,20 @@
33

44
use Symfony\Component\Config\Loader\LoaderInterface;
55
use Symfony\Component\DependencyInjection\ContainerBuilder;
6-
use Symfony\Component\Routing\RouteCollectionBuilder;
6+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
77

88
class KernelWithMappingCollectorListener extends AbstractKernel
99
{
10-
public function registerBundles(): iterable
11-
{
12-
/** @noinspection PhpIncludeInspection */
13-
$contents = require $this->getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php';
14-
foreach ($contents as $class => $envs) {
15-
if (isset($envs['all']) || isset($envs[$this->environment])) {
16-
yield new $class();
17-
}
18-
}
19-
}
20-
21-
/**
22-
* {@inheritdoc}
23-
*/
24-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
25-
{
26-
$container->setParameter('container.dumper.inline_class_loader', true);
27-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
28-
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
29-
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
30-
}
31-
3210
/**
3311
* {@inheritdoc}
3412
*/
35-
protected function configureRoutes(RouteCollectionBuilder $routes)
13+
public function getConfigDirectoryName() : string
3614
{
37-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
38-
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
15+
return 'mapping_collector_config';
3916
}
4017

41-
/**
42-
* {@inheritdoc}
43-
*/
44-
public function getConfigDirectory() : string
18+
public function getConfigDir(): string
4519
{
46-
return 'mapping_collector_config';
20+
return $this->getProjectDir().'/'.$this->getConfigDirectoryName();
4721
}
4822
}

0 commit comments

Comments
 (0)