Skip to content

Commit 0817a46

Browse files
committed
[PagePartBundle] Deprecate service class parameters
1 parent 783e880 commit 0817a46

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Kunstmaan\PagePartBundle\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
/**
9+
* @internal
10+
*/
11+
final class DeprecateClassParametersPass implements CompilerPassInterface
12+
{
13+
public function process(ContainerBuilder $container)
14+
{
15+
$expectedValues = [
16+
'kunstmaan_pagepart.page_part_configuration_reader.class' => \Kunstmaan\PagePartBundle\PagePartConfigurationReader\PagePartConfigurationReader::class,
17+
'kunstmaan_pagepart.page_part_configuration_parser.class' => \Kunstmaan\PagePartBundle\PagePartConfigurationReader\PagePartConfigurationParser::class,
18+
'kunstmaan_pagepart.page_template_configuration_reader.class' => \Kunstmaan\PagePartBundle\PageTemplate\PageTemplateConfigurationReader::class,
19+
'kunstmaan_pagepart.page_template_configuration_parser.class' => \Kunstmaan\PagePartBundle\PageTemplate\PageTemplateConfigurationParser::class,
20+
'kunstmaan_page_part.page_template.page_template_configuration_service.class' => \Kunstmaan\PagePartBundle\PageTemplate\PageTemplateConfigurationService::class,
21+
];
22+
23+
foreach ($expectedValues as $parameter => $expectedValue) {
24+
if (false === $container->hasParameter($parameter)) {
25+
continue;
26+
}
27+
28+
$currentValue = $container->getParameter($parameter);
29+
if ($currentValue !== $expectedValue) {
30+
@trigger_error(sprintf('Using the "%s" parameter to change the class of the service definition is deprecated in KunstmaanPagePartBundle 5.2 and will be removed in KunstmaanPagePartBundle 6.0. Use service decoration or a service alias instead.', $parameter), E_USER_DEPRECATED);
31+
}
32+
}
33+
}
34+
}

KunstmaanPagePartBundle.php

+6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
namespace Kunstmaan\PagePartBundle;
44

5+
use Kunstmaan\PagePartBundle\DependencyInjection\Compiler\DeprecateClassParametersPass;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
57
use Symfony\Component\HttpKernel\Bundle\Bundle;
68

79
/**
810
* KunstmaanPagePartBundle
911
*/
1012
class KunstmaanPagePartBundle extends Bundle
1113
{
14+
public function build(ContainerBuilder $container)
15+
{
16+
$container->addCompilerPass(new DeprecateClassParametersPass());
17+
}
1218
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Kunstmaan\PagePartBundle\Tests\DependencyInjection\Compiler;
4+
5+
use Kunstmaan\PagePartBundle\DependencyInjection\Compiler\DeprecateClassParametersPass;
6+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Definition;
9+
10+
class DeprecateClassParametersPassTest extends AbstractCompilerPassTestCase
11+
{
12+
protected function registerCompilerPass(ContainerBuilder $container)
13+
{
14+
$container->addCompilerPass(new DeprecateClassParametersPass());
15+
}
16+
17+
/**
18+
* @group legacy
19+
* @expectedDeprecation Using the "%s" parameter to change the class of the service definition is deprecated in KunstmaanPagePartBundle 5.2 and will be removed in KunstmaanPagePartBundle 6.0. Use service decoration or a service alias instead.
20+
*/
21+
public function testServiceClassParameterOverride()
22+
{
23+
$this->setParameter('kunstmaan_pagepart.page_part_configuration_reader.class', 'Custom\Class');
24+
25+
$this->compile();
26+
}
27+
}

0 commit comments

Comments
 (0)