Skip to content

Added a build method to the kernel to replace Bundle::build() #20107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,17 @@ protected function initializeBundles()
}
}

/**
* The extension point similar to the Bundle::build() method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, you can already achieve this by overriding Kernel::buildContainer, as long as you take care to start by calling the parent method.

*
* Use this method to register compiler passes and manipulate the container during the building process.
*
* @param ContainerBuilder $container
*/
protected function build(ContainerBuilder $container)
Copy link
Member

@javiereguiluz javiereguiluz Oct 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the name of this method. According to the Symfony naming conventions I think this should be called buildContainer() because we are not building the kernel, which is what the Kernel class is about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

Copy link
Contributor

@ro0NL ro0NL Oct 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So isnt Kernel::buildContainer the method Bundle::build tends to be, ie.. do we still need that? Should it be Bundle::buildContainer?

If you go bundles, you probably (should) go extensions anyway.

If you want a more simple bundle i'd prefer the approach from #19596.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javiereguiluz buildContainer is already taken

{
}

/**
* Gets the container class.
*
Expand Down Expand Up @@ -625,10 +636,13 @@ protected function prepareContainer(ContainerBuilder $container)
$container->addObjectResource($bundle);
}
}

foreach ($this->bundles as $bundle) {
$bundle->build($container);
}

$this->build($container);

// ensure these extensions are implicitly loaded
$container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Tests\Fixtures;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

class KernelWithoutBundles extends Kernel
{
public function registerBundles()
{
return array();
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
}

protected function build(ContainerBuilder $container)
{
$container->setParameter('test_executed', true);
}
}
9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;

class KernelTest extends TestCase
{
Expand Down Expand Up @@ -725,6 +726,14 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
$kernel->terminate(Request::create('/'), new Response());
}

public function testKernelWithoutBundles()
{
$kernel = new KernelWithoutBundles('test', true);
$kernel->boot();

$this->assertTrue($kernel->getContainer()->getParameter('test_executed'));
}

/**
* Returns a mock for the BundleInterface.
*
Expand Down