Contributed by
Iltar van der Berg
in #20107.
The bundle system has been an integral part of the Symfony framework since day one. However, some developers prefer to not use bundles in their applications except Symfony's built-in bundles and third-party bundles.
In Symfony 3.3 we've decided to simplify this by adding a new build()
method
to the Kernel
class. This method allows to register compiler passes and
manipulate the container during the building process. That's why this method
makes it easy to avoid using any bundle, even the default AppBundle.
Consider the following initial situation where you enable some compiler passes in your AppBundle and then define a bundle extension to load some configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // src/AppBundle.phpclassAppBundleextendsBundle{publicfunctionbuild(ContainerBuilder$container){$container->addCompilerPass(newSomeCompilerPass());$container->addCompilerPass(newAnotherCompilerPass());$container->addCompilerPass(newYetAnotherCompilerPass());}}// src/AppBundle/DependencyInjection/AppExtension.phpclassAppExtensionextendsExtension{publicfunctionload(array$config,ContainerBuilder$container){$binary=ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../');$snappyConfig=['pdf'=>['binary'=>realpath($binary)]];$container->prependExtensionConfig('knp_snappy',$snappyConfig);}} |
In Symfony 3.3, you can remove the AppBundle entirely and define instead thisbuild()
method in your AppKernel
class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // app/AppKernel.phpclassAppKernelextendsKernel{protectedfunctionbuild(ContainerBuilder$container){$binary=ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../');$snappyConfig=['pdf'=>['binary'=>realpath($binary)]];$container->prependExtensionConfig('knp_snappy',$snappyConfig);$container->addCompilerPass(newSomeCompilerPass());$container->addCompilerPass(newAnotherCompilerPass());$container->addCompilerPass(newYetAnotherCompilerPass());}} |