Skip to content

Commit

Permalink
Allow symfony config, dependency-injection and routing 5.1
Browse files Browse the repository at this point in the history
Symfony/config 5.1 introduces a deprecation notice when calling setDeprecation() with less than 3 args. An internal helper class has been added as a BC layer.
  • Loading branch information
franmomu authored and jordisala1991 committed Sep 3, 2020
1 parent 3ad3910 commit 7cc6f5b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 11 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"sonata-project/form-extensions": "^0.1.1 || ^1.4",
"sonata-project/twig-extensions": "^0.1.1 || ^1.3",
"symfony/asset": "^4.4 || ^5.1",
"symfony/config": "^4.4",
"symfony/config": "^4.4 || ^5.1",
"symfony/console": "^4.4",
"symfony/dependency-injection": "^4.4.8",
"symfony/dependency-injection": "^4.4.8 || ^5.1",
"symfony/doctrine-bridge": "^4.4",
"symfony/event-dispatcher": "^4.4",
"symfony/event-dispatcher-contracts": "^1.1 || ^2.0",
Expand All @@ -48,7 +48,7 @@
"symfony/http-kernel": "^4.4",
"symfony/options-resolver": "^4.4 || ^5.1",
"symfony/property-access": "^4.4 || ^5.1",
"symfony/routing": "^4.4",
"symfony/routing": "^4.4 || ^5.1",
"symfony/security-acl": "^3.1",
"symfony/security-bundle": "^4.4",
"symfony/security-core": "^4.4",
Expand Down
6 changes: 5 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sonata\AdminBundle\DependencyInjection;

use Sonata\AdminBundle\Util\BCDeprecationParameters;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand Down Expand Up @@ -168,7 +169,10 @@ public function getConfigTreeBuilder()
// NEXT_MAJOR : remove this option
->booleanNode('legacy_twig_text_extension')
->info('Use text filters from "twig/extensions" instead of those provided by "twig/string-extra".')
->setDeprecated('The child node "%node%" at path "%path%" is deprecated since sonata-project/admin-bundle 3.70 and will be removed in 4.0.')
->setDeprecated(...BCDeprecationParameters::forConfig(
'The child node "%node%" at path "%path%" is deprecated since sonata-project/admin-bundle 3.70 and will be removed in 4.0.',
'3.70'
))
->defaultValue(static function (): bool {
@trigger_error(
'Using `true` as value for "sonata_admin.options.legacy_twig_text_extension" option is deprecated since sonata-project/admin-bundle 3.64. '
Expand Down
6 changes: 5 additions & 1 deletion src/Resources/config/commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sonata\AdminBundle\Command\GenerateObjectAclCommand;
use Sonata\AdminBundle\Command\ListAdminCommand;
use Sonata\AdminBundle\Command\SetupAclCommand;
use Sonata\AdminBundle\Util\BCDeprecationParameters;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

Expand All @@ -30,7 +31,10 @@
->tag('console.command', [
'command' => 'cache:create-cache-class',
])
->deprecate('The "%service_id%" service is deprecated since sonata-project/admin-bundle 3.39.0 and will be removed in 4.0.')
->deprecate(...BCDeprecationParameters::forConfig(
'The "%service_id%" service is deprecated since sonata-project/admin-bundle 3.39.0 and will be removed in 4.0.',
'3.39.0'
))
->args([
'%kernel.cache_dir%',
'%kernel.debug%',
Expand Down
15 changes: 11 additions & 4 deletions src/Resources/config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Sonata\AdminBundle\Translator\NoopLabelTranslatorStrategy;
use Sonata\AdminBundle\Translator\UnderscoreLabelTranslatorStrategy;
use Sonata\AdminBundle\Twig\GlobalVariables;
use Sonata\AdminBundle\Util\BCDeprecationParameters;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

Expand Down Expand Up @@ -136,10 +137,10 @@
->tag('jms_translation.extractor', [
'alias' => 'sonata_admin',
])
->deprecate(sprintf(
->deprecate(...BCDeprecationParameters::forConfig(sprintf(
'The service "%%service_id%%" is deprecated since sonata-project/admin-bundle 3.72 and will be removed in 4.0. Use "%s" service instead.',
Sonata\AdminBundle\Translator\Extractor\AdminExtractor::class
))
), '3.72'))
->args([
new ReferenceConfigurator('sonata.admin.pool'),
(new ReferenceConfigurator('logger'))->nullOnInvalid(),
Expand All @@ -160,7 +161,10 @@
// NEXT_MAJOR: Remove this service.
->set('sonata.admin.controller.admin', HelperController::class)
->public()
->deprecate('The controller service "%service_id%" is deprecated in favor of several action services since sonata-project/admin-bundle 3.38.0 and will be removed in 4.0.')
->deprecate(...BCDeprecationParameters::forConfig(
'The controller service "%service_id%" is deprecated in favor of several action services since sonata-project/admin-bundle 3.38.0 and will be removed in 4.0.',
'3.38.0'
))
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.admin.pool'),
Expand All @@ -181,7 +185,10 @@
// NEXT_MAJOR: Remove this service.
->set('sonata.admin.exporter', Exporter::class)
->public()
->deprecate('The service "%service_id%" is deprecated since sonata-project/admin-bundle 3.14.0 and will be removed in 4.0. Use "sonata.exporter.exporter" service instead.')
->deprecate(...BCDeprecationParameters::forConfig(
'The service "%service_id%" is deprecated since sonata-project/admin-bundle 3.14.0 and will be removed in 4.0. Use "sonata.exporter.exporter" service instead.',
'3.14.0'
))

->set('sonata.admin.search.handler', SearchHandler::class)
->public()
Expand Down
6 changes: 5 additions & 1 deletion src/Resources/config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sonata\AdminBundle\Menu\Matcher\Voter\ChildrenVoter;
use Sonata\AdminBundle\Menu\MenuBuilder;
use Sonata\AdminBundle\Menu\Provider\GroupMenuProvider;
use Sonata\AdminBundle\Util\BCDeprecationParameters;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

Expand Down Expand Up @@ -60,7 +61,10 @@
// NEXT_MAJOR: Remove this service.
->set('sonata.admin.menu.matcher.voter.children', ChildrenVoter::class)
->public()
->deprecate('The "%service_id%" service is deprecated since sonata-project/admin-bundle 3.28 and will be removed in 4.0.')
->deprecate(...BCDeprecationParameters::forConfig(
'The "%service_id%" service is deprecated since sonata-project/admin-bundle 3.28 and will be removed in 4.0.',
'3.28'
))
->args([
new ReferenceConfigurator('knp_menu.matcher'),
])
Expand Down
6 changes: 5 additions & 1 deletion src/Resources/config/twig_string.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Sonata\AdminBundle\Twig\Extension\DeprecatedTextExtension;
use Sonata\AdminBundle\Twig\Extension\StringExtension;
use Sonata\AdminBundle\Util\BCDeprecationParameters;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand All @@ -27,6 +28,9 @@
// NEXT_MAJOR: Remove this service.
->set('sonata.deprecated_text.twig.extension', DeprecatedTextExtension::class)
->tag('twig.extension')
->deprecate('The "%service_id%" service is deprecated since sonata-project/admin-bundle 3.70. You should stop using it, as it will be removed in 4.0.')
->deprecate(...BCDeprecationParameters::forConfig(
'The "%service_id%" service is deprecated since sonata-project/admin-bundle 3.70. You should stop using it, as it will be removed in 4.0.',
'3.70'
))
;
};
41 changes: 41 additions & 0 deletions src/Util/BCDeprecationParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Util;

use Symfony\Component\Config\Definition\BaseNode;

/**
* This class is a BC layer for deprecation messages for symfony/config < 5.1.
* Remove this class when dropping support for symfony/config < 5.1.
*
* @internal
*/
final class BCDeprecationParameters
{
/**
* @return string[]
*/
public static function forConfig(string $message, string $version): array
{
if (method_exists(BaseNode::class, 'getDeprecation')) {
return [
'sonata-project/admin-bundle',
$version,
$message,
];
}

return [$message];
}
}

0 comments on commit 7cc6f5b

Please sign in to comment.