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

[FormBundle] Deprecate service class parameters #2303

Merged
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,31 @@
<?php

namespace Kunstmaan\FormBundle\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_form.form_mailer.class' => \Kunstmaan\FormBundle\Helper\FormMailer::class,
'kunstmaan_form.form_handler.class' => \Kunstmaan\FormBundle\Helper\FormHandler::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 KunstmaanFormBundle 5.2 and will be removed in KunstmaanFormBundle 6.0. Use service decoration or a service alias instead.', $parameter), E_USER_DEPRECATED);
}
}
}
}
6 changes: 6 additions & 0 deletions src/Kunstmaan/FormBundle/KunstmaanFormBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

namespace Kunstmaan\FormBundle;

use Kunstmaan\FormBundle\DependencyInjection\Compiler\DeprecateClassParametersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* KunstmaanFormBundle
*/
class KunstmaanFormBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new DeprecateClassParametersPass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Kunstmaan\FormBundle\Tests\DependencyInjection\Compiler;

use Kunstmaan\FormBundle\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 KunstmaanFormBundle 5.2 and will be removed in KunstmaanFormBundle 6.0. Use service decoration or a service alias instead.
*/
public function testServiceClassParameterOverride()
{
$this->setParameter('kunstmaan_form.form_mailer.class', 'Custom\Class');

$this->compile();
}
}