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

This commit is contained in:
Nicolas Grekas 2019-12-07 14:19:06 +01:00
parent 65a988880d
commit a689807387
4 changed files with 29 additions and 7 deletions

View File

@ -7,6 +7,7 @@ CHANGELOG
* Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`. * Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`.
* Deprecated not overriding `MicroKernelTrait::configureRouting()`. * 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 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 5.0.0
----- -----

View File

@ -72,6 +72,27 @@ trait MicroKernelTrait
*/ */
abstract protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader); 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} * {@inheritdoc}
*/ */
@ -100,8 +121,8 @@ trait MicroKernelTrait
} }
$this->configureContainer($container, $loader); $this->configureContainer($container, $loader);
$container->addObjectResource($this); $container->addObjectResource($this);
$container->fileExists($this->getProjectDir().'/config/bundles.php');
}); });
} }

View File

@ -151,8 +151,8 @@ class PhpDumper extends Dumper
$this->namespace = $options['namespace']; $this->namespace = $options['namespace'];
$this->asFiles = $options['as_files']; $this->asFiles = $options['as_files'];
$this->hotPathTag = $options['hot_path_tag']; $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->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->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']; $this->serviceLocatorTag = $options['service_locator_tag'];
if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) { if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) {

View File

@ -227,7 +227,7 @@ class PhpDumperTest extends TestCase
->addError('No-no-no-no'); ->addError('No-no-no-no');
$container->compile(); $container->compile();
$dumper = new PhpDumper($container); $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) { if ('\\' === \DIRECTORY_SEPARATOR) {
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump); $dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump);
} }
@ -297,7 +297,7 @@ class PhpDumperTest extends TestCase
->setLazy(true); ->setLazy(true);
$container->compile(); $container->compile();
$dumper = new PhpDumper($container); $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) { if ('\\' === \DIRECTORY_SEPARATOR) {
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo_lazy.php', '/Fixtures/includes/foo_lazy.php', $dump); $dump = str_replace('\\\\Fixtures\\\\includes\\\\foo_lazy.php', '/Fixtures/includes/foo_lazy.php', $dump);
@ -478,7 +478,7 @@ class PhpDumperTest extends TestCase
$container->compile(); $container->compile();
$dumper = new PhpDumper($container); $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'; require self::$fixturesPath.'/php/services26.php';
$container = new \Symfony_DI_PhpDumper_Test_EnvParameters(); $container = new \Symfony_DI_PhpDumper_Test_EnvParameters();
@ -944,7 +944,7 @@ class PhpDumperTest extends TestCase
$dumper = new PhpDumper($container); $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() public function testExpressionReferencingPrivateService()