Skip to content
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

[NodeSearchBundle] Deprecate service class parameters #2293

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Kunstmaan\NodeSearchBundle\DependencyInjection\Compiler;

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

/**
* @internal
*/
final class DeprecateClassParametersPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$expectedValues = [
'kunstmaan_node_search.search_configuration.node.class' => \Kunstmaan\NodeSearchBundle\Configuration\NodePagesConfiguration::class,
'kunstmaan_node_search.search.node.class' => \Kunstmaan\NodeSearchBundle\Search\NodeSearcher::class,
'kunstmaan_node_search.search_service.class' => \Kunstmaan\NodeSearchBundle\Services\SearchService::class,
'kunstmaan_node_search.node_index_update.listener.class' => \Kunstmaan\NodeSearchBundle\EventListener\NodeIndexUpdateEventListener::class,
];

foreach ($expectedValues as $parameter => $expectedValue) {
if (false === $container->hasParameter($parameter)) {
continue;
}

$currentValue = $container->getParameter($parameter);
if ($currentValue !== $expectedValue) {
@trigger_error(sprintf('Using the "%s" parameter to change the class of the service definition is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Use service decoration or a service alias instead.', $parameter), E_USER_DEPRECATED);
}
}
}
}
2 changes: 2 additions & 0 deletions src/Kunstmaan/NodeSearchBundle/KunstmaanNodeSearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kunstmaan\NodeSearchBundle;

use Kunstmaan\NodeSearchBundle\DependencyInjection\Compiler\DeprecateClassParametersPass;
use Kunstmaan\NodeSearchBundle\DependencyInjection\Compiler\NodeSearcherCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -14,5 +15,6 @@ class KunstmaanNodeSearchBundle extends Bundle
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new NodeSearcherCompilerPass());
$container->addCompilerPass(new DeprecateClassParametersPass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Kunstmaan\NodeSearchBundle\Tests\DependencyInjection\Compiler;

use Kunstmaan\NodeSearchBundle\DependencyInjection\Compiler\DeprecateClassParametersPass;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class DeprecateClassParametersPassTest extends AbstractCompilerPassTestCase
{
protected function registerCompilerPass(ContainerBuilder $container)
{
$container->addCompilerPass(new DeprecateClassParametersPass());
}

/**
* @group legacy
* @expectedDeprecation Using the "%s" parameter to change the class of the service definition is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Use service decoration or a service alias instead.
*/
public function testServiceClassParameterOverride()
{
$this->setParameter('kunstmaan_node_search.search_configuration.node.class', 'Custom\Class');

$this->compile();
}
}