Skip to content

[FrameworkBundle][Config] Move ConfigCachePass from FrameworkBundle to Config #21375

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 28, 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
5 changes: 5 additions & 0 deletions UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ FrameworkBundle
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpKernel\EventListener\TestSessionListener`
class instead.

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been
deprecated and will be removed in 4.0. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass`
class instead.


HttpKernel
-----------

Expand Down
4 changes: 4 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ FrameworkBundle
removed. Use the `Symfony\Component\HttpKernel\EventListener\TestSessionListener`
class instead.

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been removed.
Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` class instead.


HttpFoundation
---------------

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ CHANGELOG
* Deprecated `FormPass`, use `Symfony\Component\Form\DependencyInjection\FormPass` instead
* Deprecated `SessionListener`
* Deprecated `TestSessionListener`
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`.
Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead.

3.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,18 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\DependencyInjection\ConfigCachePass as BaseConfigCachePass;

@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Config\DependencyInjection\ConfigCachePass instead.', ConfigCachePass::class), E_USER_DEPRECATED);

/**
* Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority.
*
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseConfigCachePass} instead.
*
* @author Matthias Pigulla <mp@webfactory.de>
* @author Benjamin Klotz <bk@webfactory.de>
*/
class ConfigCachePass implements CompilerPassInterface
class ConfigCachePass extends BaseConfigCachePass
{
use PriorityTaggedServiceTrait;

public function process(ContainerBuilder $container)
{
$resourceCheckers = $this->findAndSortTaggedServices('config_cache.resource_checker', $container);

if (empty($resourceCheckers)) {
return;
}

$container->getDefinition('config_cache_factory')->replaceArgument(0, $resourceCheckers);
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
use Symfony\Component\Debug\ErrorHandler;
Expand Down Expand Up @@ -108,7 +108,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING, -32);
$container->addCompilerPass(new ConfigCachePass());
$this->addCompilerPassIfExists($container, ConfigCachePass::class);
$container->addCompilerPass(new CacheCollectorPass());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;

/**
* @group legacy
*/
class ConfigCachePassTest extends TestCase
{
public function testThatCheckersAreProcessedInPriorityOrder()
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* added `ReflectionClassResource` class
* added second `$exists` constructor argument to `ClassExistenceResource`
* made `ClassExistenceResource` work with interfaces and traits
* added `ConfigCachePass` (originally in FrameworkBundle)

3.0.0
-----
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\Config\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority.
*
* @author Matthias Pigulla <mp@webfactory.de>
* @author Benjamin Klotz <bk@webfactory.de>
*/
class ConfigCachePass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

private $factoryServiceId;
private $resourceCheckerTag;

public function __construct($factoryServiceId = 'config_cache_factory', $resourceCheckerTag = 'config_cache.resource_checker')
{
$this->factoryServiceId = $factoryServiceId;
$this->resourceCheckerTag = $resourceCheckerTag;
}

public function process(ContainerBuilder $container)
{
$resourceCheckers = $this->findAndSortTaggedServices($this->resourceCheckerTag, $container);

if (empty($resourceCheckers)) {
return;
}

$container->getDefinition($this->factoryServiceId)->replaceArgument(0, $resourceCheckers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\Config\Tests\DependencyInjection;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;

class ConfigCachePassTest extends TestCase
{
public function testThatCheckersAreProcessedInPriorityOrder()
{
$services = array(
'checker_2' => array(0 => array('priority' => 100)),
'checker_1' => array(0 => array('priority' => 200)),
'checker_3' => array(0 => array()),
);

$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();

$container->expects($this->atLeastOnce())
->method('findTaggedServiceIds')
->will($this->returnValue($services));
$container->expects($this->atLeastOnce())
->method('getDefinition')
->with('config_cache_factory')
->will($this->returnValue($definition));

$definition->expects($this->once())
->method('replaceArgument')
->with(0, array(
new Reference('checker_1'),
new Reference('checker_2'),
new Reference('checker_3'),
));

$pass = new ConfigCachePass();
$pass->process($container);
}

public function testThatCheckersCanBeMissing()
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();

$container->expects($this->atLeastOnce())
->method('findTaggedServiceIds')
->will($this->returnValue(array()));

$pass = new ConfigCachePass();
$pass->process($container);
}
}
6 changes: 5 additions & 1 deletion src/Symfony/Component/Config/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"symfony/filesystem": "~2.8|~3.0"
},
"require-dev": {
"symfony/yaml": "~3.0"
"symfony/yaml": "~3.0",
"symfony/dependency-injection": "~3.2"
},
"conflict": {
"symfony/dependency-injection": "<3.2"
},
"suggest": {
"symfony/yaml": "To use the yaml reference dumper"
Expand Down