Skip to content
Permalink
Browse files

feature #34872 [FrameworkBundle] Added flex-compatible default implem…

…entations for `MicroKernelTrait::registerBundles()` and `getProjectDir()` (nicolas-grekas)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[FrameworkBundle] Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()`

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

I think it's safe now to migrate some flex-based defaults from the recipe to the bundle.
No BC break here as all existing kernels already redefine this method.

Commits
-------

a689807 [FrameworkBundle] Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()`
  • Loading branch information
nicolas-grekas committed Dec 13, 2019
2 parents a6d1567 + a689807 commit 44458126b58e8d427db2d3c06dc6bad51d1f54ec
@@ -7,6 +7,7 @@ CHANGELOG
* Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`.
* Deprecated not overriding `MicroKernelTrait::configureRouting()`.
* Added a new `mailer.message_bus` option to configure or disable the message bus to use to send mails.
* Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()`

5.0.0
-----
@@ -72,6 +72,27 @@ protected function configureRouting(RoutingConfigurator $routes): void
*/
abstract protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader);

/**
* {@inheritdoc}
*/
public function getProjectDir(): string
{
return \dirname((new \ReflectionObject($this))->getFileName(), 2);
}

/**
* {@inheritdoc}
*/
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}

/**
* {@inheritdoc}
*/
@@ -100,8 +121,8 @@ public function registerContainerConfiguration(LoaderInterface $loader)
}

$this->configureContainer($container, $loader);

$container->addObjectResource($this);
$container->fileExists($this->getProjectDir().'/config/bundles.php');
});
}

@@ -151,8 +151,8 @@ public function dump(array $options = [])
$this->namespace = $options['namespace'];
$this->asFiles = $options['as_files'];
$this->hotPathTag = $options['hot_path_tag'];
$this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && $this->container->hasParameter($options['inline_factories_parameter']) && $this->container->getParameter($options['inline_factories_parameter']);
$this->inlineRequires = $options['inline_class_loader_parameter'] && $this->container->hasParameter($options['inline_class_loader_parameter']) && $this->container->getParameter($options['inline_class_loader_parameter']);
$this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && (!$this->container->hasParameter($options['inline_factories_parameter']) || $this->container->getParameter($options['inline_factories_parameter']));
$this->inlineRequires = $options['inline_class_loader_parameter'] && ($this->container->hasParameter($options['inline_class_loader_parameter']) ? $this->container->getParameter($options['inline_class_loader_parameter']) : \PHP_VERSION_ID < 70400);
$this->serviceLocatorTag = $options['service_locator_tag'];

if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) {
@@ -227,7 +227,7 @@ public function testDumpAsFiles()
->addError('No-no-no-no');
$container->compile();
$dumper = new PhpDumper($container);
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot']), true);
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true);
if ('\\' === \DIRECTORY_SEPARATOR) {
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump);
}
@@ -297,7 +297,7 @@ public function testNonSharedLazyDumpAsFiles()
->setLazy(true);
$container->compile();
$dumper = new PhpDumper($container);
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__]), true);
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true);

if ('\\' === \DIRECTORY_SEPARATOR) {
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo_lazy.php', '/Fixtures/includes/foo_lazy.php', $dump);
@@ -478,7 +478,7 @@ public function testEnvParameter()
$container->compile();
$dumper = new PhpDumper($container);

$this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php']));
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]));

require self::$fixturesPath.'/php/services26.php';
$container = new \Symfony_DI_PhpDumper_Test_EnvParameters();
@@ -944,7 +944,7 @@ public function testArrayParameters()

$dumper = new PhpDumper($container);

$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php'])));
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false])));
}

public function testExpressionReferencingPrivateService()

0 comments on commit 4445812

Please sign in to comment.
You can’t perform that action at this time.