Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99f60dc

Browse files
committed
feature#20107 Added a build method to the kernel to replace Bundle::build() (iltar)
This PR was merged into the 3.3-dev branch.Discussion----------Added a build method to the kernel to replace Bundle::build()| Q | A || --- | --- || Branch? | master || Bug fix? | no || New feature? | yes || BC breaks? | no || Deprecations? | no || Tests pass? | yes || Fixed tickets |#20099 || License | MIT || Doc PR | ~ |Adds a DX method to make it easier to omit using an AppBundle in your application.**Old situation**``` php// src/AppBundle.phpclass AppBundle extends Bundle{ public function build(ContainerBuilder $container) { $container->addCompilerPass(new SomeCompilerPass()); $container->addCompilerPass(new AnotherCompilerPass()); $container->addCompilerPass(new YetAnotherCompilerPass()); }}// src/DependencyInjection/AppExtension.phpclass AppExtension extends Extension{ public function load(array $config, ContainerBuilder $container) { $binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../'); $snappyConfig = ['pdf' => ['binary' => realpath($binary)]]; $container->prependExtensionConfig('knp_snappy', $snappyConfig); }}```**New situation**``` php// rm src/AppBundle.php// rm src/DependencyInjection/AppExtension.php// app/AppKernel.phpclass AppKernel extends Kernel{ protected function build(ContainerBuilder $container) { $binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../'); $snappyConfig = ['pdf' => ['binary' => realpath($binary)]]; $container->prependExtensionConfig('knp_snappy', $snappyConfig); $container->addCompilerPass(new SomeCompilerPass()); $container->addCompilerPass(new AnotherCompilerPass()); $container->addCompilerPass(new YetAnotherCompilerPass()); }}```Still missing tests, wondering if worth adding in this state first.Commits-------62e80fc Added build and class cache to kernel
2 parents0e92e0a +62e80fc commit99f60dc

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

‎src/Symfony/Component/HttpKernel/Kernel.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,17 @@ protected function initializeBundles()
466466
}
467467
}
468468

469+
/**
470+
* The extension point similar to the Bundle::build() method.
471+
*
472+
* Use this method to register compiler passes and manipulate the container during the building process.
473+
*
474+
* @param ContainerBuilder $container
475+
*/
476+
protectedfunctionbuild(ContainerBuilder$container)
477+
{
478+
}
479+
469480
/**
470481
* Gets the container class.
471482
*
@@ -625,10 +636,13 @@ protected function prepareContainer(ContainerBuilder $container)
625636
$container->addObjectResource($bundle);
626637
}
627638
}
639+
628640
foreach ($this->bundlesas$bundle) {
629641
$bundle->build($container);
630642
}
631643

644+
$this->build($container);
645+
632646
// ensure these extensions are implicitly loaded
633647
$container->getCompilerPassConfig()->setMergePass(newMergeExtensionConfigurationPass($extensions));
634648
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\HttpKernel\Tests\Fixtures;
13+
14+
useSymfony\Component\Config\Loader\LoaderInterface;
15+
useSymfony\Component\DependencyInjection\ContainerBuilder;
16+
useSymfony\Component\HttpKernel\Kernel;
17+
18+
class KernelWithoutBundlesextends Kernel
19+
{
20+
publicfunctionregisterBundles()
21+
{
22+
returnarray();
23+
}
24+
25+
publicfunctionregisterContainerConfiguration(LoaderInterface$loader)
26+
{
27+
}
28+
29+
protectedfunctionbuild(ContainerBuilder$container)
30+
{
31+
$container->setParameter('test_executed',true);
32+
}
33+
}

‎src/Symfony/Component/HttpKernel/Tests/KernelTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
useSymfony\Component\HttpFoundation\Response;
2222
useSymfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
2323
useSymfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
24+
useSymfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;
2425

2526
class KernelTestextends TestCase
2627
{
@@ -725,6 +726,14 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
725726
$kernel->terminate(Request::create('/'),newResponse());
726727
}
727728

729+
publicfunctiontestKernelWithoutBundles()
730+
{
731+
$kernel =newKernelWithoutBundles('test',true);
732+
$kernel->boot();
733+
734+
$this->assertTrue($kernel->getContainer()->getParameter('test_executed'));
735+
}
736+
728737
/**
729738
* Returns a mock for the BundleInterface.
730739
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp