Skip to content

Commit ad9c5f5

Browse files
authored
Suppress deprecations on deprecating legacy services (php-translation#445)
* Suppress deprecations on deprecating legacy services * Apply PHP CS Fixer recommendations * Fix the Kernel version ID number * Simplify code: Remove unnecessary var * Rename the method to registerDeprecatedServices()
1 parent 84c843d commit ad9c5f5

File tree

10 files changed

+141
-118
lines changed

10 files changed

+141
-118
lines changed

DependencyInjection/TranslationExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ public function load(array $configs, ContainerBuilder $container): void
4747
$configuration = new Configuration($container);
4848
$config = $this->processConfiguration($configuration, $configs);
4949
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
50+
$legacyLoader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/legacy'));
5051

5152
$loader->load('services.yaml');
53+
$legacyLoader->load('services.php');
5254
$loader->load('extractors.yaml');
55+
$legacyLoader->load('extractors.php');
5356

5457
// Add major version to extractor
5558
$container->getDefinition(FormTypeChoices::class)
@@ -74,6 +77,7 @@ public function load(array $configs, ContainerBuilder $container): void
7477

7578
if ($config['edit_in_place']['enabled']) {
7679
$loader->load('edit_in_place.yaml');
80+
$legacyLoader->load('edit_in_place.php');
7781
$this->enableEditInPlace($container, $config);
7882
}
7983

@@ -89,6 +93,7 @@ public function load(array $configs, ContainerBuilder $container): void
8993
}
9094

9195
$loader->load('console.yaml');
96+
$legacyLoader->load('console.php');
9297
}
9398

9499
/**

Legacy/LegacyHelper.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Translation\Bundle\Legacy;
1313

14+
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
1415
use Symfony\Component\HttpFoundation\RequestStack;
16+
use Symfony\Component\HttpKernel\Kernel;
1517

1618
/**
1719
* A legacy helper to suppress deprecations on RequestStack.
@@ -28,4 +30,30 @@ public static function getMainRequest(RequestStack $requestStack)
2830

2931
return $requestStack->getMasterRequest();
3032
}
33+
34+
/**
35+
* @param array[string $id, string $parent, ?bool $isPublic] $legacyServices
36+
*/
37+
public static function registerDeprecatedServices(ServicesConfigurator $servicesConfigurator, array $legacyServices)
38+
{
39+
foreach ($legacyServices as $legacyService) {
40+
$id = $legacyService[0];
41+
$parent = $legacyService[1];
42+
$isPublic = $legacyService[2] ?? false;
43+
44+
// Declare legacy services to remove in next major release
45+
$service = $servicesConfigurator->set($id)
46+
->parent($parent);
47+
48+
if (Kernel::VERSION_ID < 50100) {
49+
$service->deprecate('Since php-translation/symfony-bundle 0.10.0: The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.');
50+
} else {
51+
$service->deprecate('php-translation/symfony-bundle', '0.10.0', 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.');
52+
}
53+
54+
if ($isPublic) {
55+
$service->public();
56+
}
57+
}
58+
}
3159
}

Resources/config/console.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,3 @@ services:
6565
- '@Translation\Bundle\Service\StorageManager'
6666
tags:
6767
- { name: console.command, command: translation:sync }
68-
69-
# To remove in next major release
70-
php_translator.console.delete_obsolete:
71-
parent: Translation\Bundle\Command\DeleteObsoleteCommand
72-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
73-
php_translator.console.download:
74-
parent: Translation\Bundle\Command\DownloadCommand
75-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
76-
php_translator.console.extract:
77-
parent: Translation\Bundle\Command\ExtractCommand
78-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
79-
php_translator.console.status:
80-
parent: Translation\Bundle\Command\StatusCommand
81-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
82-
php_translator.console.sync:
83-
parent: Translation\Bundle\Command\SyncCommand
84-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'

Resources/config/edit_in_place.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,3 @@ services:
3636
- ~
3737
tags:
3838
- { name: 'twig.extension' }
39-
40-
# To remove in next major release
41-
php_translation.edit_in_place.response_listener:
42-
parent: Translation\Bundle\EventListener\EditInPlaceResponseListener
43-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
44-
php_translation.edit_in_place.activator:
45-
parent: Translation\Bundle\EditInPlace\Activator
46-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
47-
php_translator.edit_in_place.xtrans_html_translator:
48-
parent: Translation\Bundle\Translator\EditInPlaceTranslator
49-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
50-
php_translation.edit_in_place.extension.trans:
51-
parent: Translation\Bundle\Twig\EditInPlaceExtension
52-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'

Resources/config/extractors.yaml

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,5 @@ services:
2424
tags:
2525
- { name: 'php_translation.visitor', type: 'twig' }
2626

27-
# To remove in next major release
28-
php_translation.extractor.php:
29-
alias: Translation\Extractor\FileExtractor\PHPFileExtractor
30-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
31-
php_translation.extractor.twig:
32-
alias: Translation\Extractor\FileExtractor\TwigFileExtractor
33-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
34-
php_translation.extractor.php.visitor.ContainerAwareTrans:
35-
alias: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans
36-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
37-
php_translation.extractor.php.visitor.ContainerAwareTransChoice:
38-
alias: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice
39-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
40-
php_translation.extractor.php.visitor.FlashMessage:
41-
alias: Translation\Extractor\Visitor\Php\Symfony\FlashMessage
42-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
43-
php_translation.extractor.php.visitor.FormTypeChoices:
44-
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices
45-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
46-
php_translation.extractor.php.visitor.FormTypeEmptyValue:
47-
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue
48-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
49-
php_translation.extractor.php.visitor.FormTypeHelp:
50-
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp
51-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
52-
php_translation.extractor.php.visitor.FormTypeInvalidMessage:
53-
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage
54-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
55-
php_translation.extractor.php.visitor.FormTypeLabelExplicit:
56-
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit
57-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
58-
php_translation.extractor.php.visitor.FormTypeLabelImplicit:
59-
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit
60-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
61-
php_translation.extractor.php.visitor.FormTypePlaceholder:
62-
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder
63-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
64-
php_translation.extractor.php.visitor.ValidationAnnotation:
65-
alias: Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation
66-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
67-
php_translation.extractor.php.visitor.SourceLocationContainerVisitor:
68-
alias: Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor
69-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
70-
php_translation.extractor.twig.factory.twig:
71-
alias: Translation\Extractor\Visitor\Twig\TwigVisitor
72-
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
73-
7427
Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation:
7528
arguments: ['@validator']

Resources/config/legacy/console.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Translation\Bundle\Command\DeleteObsoleteCommand;
6+
use Translation\Bundle\Command\DownloadCommand;
7+
use Translation\Bundle\Command\ExtractCommand;
8+
use Translation\Bundle\Command\StatusCommand;
9+
use Translation\Bundle\Command\SyncCommand;
10+
use Translation\Bundle\Legacy\LegacyHelper;
11+
12+
return function (ContainerConfigurator $configurator) {
13+
LegacyHelper::registerDeprecatedServices($configurator->services(), [
14+
['php_translator.console.delete_obsolete', DeleteObsoleteCommand::class],
15+
['php_translator.console.download', DownloadCommand::class],
16+
['php_translator.console.extract', ExtractCommand::class],
17+
['php_translator.console.status', StatusCommand::class],
18+
['php_translator.console.sync', SyncCommand::class],
19+
]);
20+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Translation\Bundle\EditInPlace\Activator;
6+
use Translation\Bundle\EventListener\EditInPlaceResponseListener;
7+
use Translation\Bundle\Legacy\LegacyHelper;
8+
use Translation\Bundle\Translator\EditInPlaceTranslator;
9+
use Translation\Bundle\Twig\EditInPlaceExtension;
10+
11+
return function (ContainerConfigurator $configurator) {
12+
LegacyHelper::registerDeprecatedServices($configurator->services(), [
13+
['php_translation.edit_in_place.response_listener', EditInPlaceResponseListener::class],
14+
['php_translation.edit_in_place.activator', Activator::class],
15+
['php_translator.edit_in_place.xtrans_html_translator', EditInPlaceTranslator::class],
16+
['php_translation.edit_in_place.extension.trans', EditInPlaceExtension::class],
17+
]);
18+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Translation\Bundle\Legacy\LegacyHelper;
6+
use Translation\Extractor\FileExtractor\PHPFileExtractor;
7+
use Translation\Extractor\FileExtractor\TwigFileExtractor;
8+
use Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor;
9+
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans;
10+
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice;
11+
use Translation\Extractor\Visitor\Php\Symfony\FlashMessage;
12+
use Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices;
13+
use Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue;
14+
use Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp;
15+
use Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage;
16+
use Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit;
17+
use Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit;
18+
use Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder;
19+
use Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation;
20+
use Translation\Extractor\Visitor\Twig\TwigVisitor;
21+
22+
return function (ContainerConfigurator $configurator) {
23+
LegacyHelper::registerDeprecatedServices($configurator->services(), [
24+
['php_translation.extractor.php', PHPFileExtractor::class],
25+
['php_translation.extractor.twig', TwigFileExtractor::class],
26+
['php_translation.extractor.php.visitor.ContainerAwareTrans', ContainerAwareTrans::class],
27+
['php_translation.extractor.php.visitor.ContainerAwareTransChoice', ContainerAwareTransChoice::class],
28+
['php_translation.extractor.php.visitor.FlashMessage', FlashMessage::class],
29+
['php_translation.extractor.php.visitor.FormTypeChoices', FormTypeChoices::class],
30+
['php_translation.extractor.php.visitor.FormTypeEmptyValue', FormTypeEmptyValue::class],
31+
['php_translation.extractor.php.visitor.FormTypeHelp', FormTypeHelp::class],
32+
['php_translation.extractor.php.visitor.FormTypeInvalidMessage', FormTypeInvalidMessage::class],
33+
['php_translation.extractor.php.visitor.FormTypeLabelExplicit', FormTypeLabelExplicit::class],
34+
['php_translation.extractor.php.visitor.FormTypeLabelImplicit', FormTypeLabelImplicit::class],
35+
['php_translation.extractor.php.visitor.FormTypePlaceholder', FormTypePlaceholder::class],
36+
['php_translation.extractor.php.visitor.ValidationAnnotation', ValidationAnnotation::class],
37+
['php_translation.extractor.php.visitor.SourceLocationContainerVisitor', SourceLocationContainerVisitor::class],
38+
['php_translation.extractor.twig.factory.twig', TwigVisitor::class],
39+
]);
40+
};

Resources/config/legacy/services.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Translation\Bundle\Catalogue\CatalogueCounter;
6+
use Translation\Bundle\Catalogue\CatalogueFetcher;
7+
use Translation\Bundle\Catalogue\CatalogueManager;
8+
use Translation\Bundle\Catalogue\CatalogueWriter;
9+
use Translation\Bundle\Legacy\LegacyHelper;
10+
use Translation\Bundle\Service\CacheClearer;
11+
use Translation\Bundle\Service\ConfigurationManager;
12+
use Translation\Bundle\Service\Importer;
13+
use Translation\Bundle\Service\StorageManager;
14+
use Translation\Bundle\Twig\TranslationExtension;
15+
use Translation\Extractor\Extractor;
16+
17+
return function (ContainerConfigurator $configurator) {
18+
LegacyHelper::registerDeprecatedServices($configurator->services(), [
19+
['php_translation.catalogue_fetcher', CatalogueFetcher::class, true],
20+
['php_translation.catalogue_writer', CatalogueWriter::class, true],
21+
['php_translation.catalogue_manager', CatalogueManager::class, true],
22+
['php_translation.extractor', Extractor::class],
23+
['php_translation.storage_manager', StorageManager::class, true],
24+
['php_translation.configuration_manager', ConfigurationManager::class, true],
25+
['php_translation.importer', Importer::class, true],
26+
['php_translation.cache_clearer', CacheClearer::class, true],
27+
['php_translation.catalogue_counter', CatalogueCounter::class, true],
28+
['php_translation.twig_extension', TranslationExtension::class],
29+
]);
30+
};

Resources/config/services.yaml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,3 @@ services:
4343
arguments: ['@translator', '%kernel.debug%']
4444
tags:
4545
- { name: twig.extension }
46-
47-
# To remove in next major release
48-
php_translation.catalogue_fetcher:
49-
parent: Translation\Bundle\Catalogue\CatalogueFetcher
50-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
51-
public: true
52-
php_translation.catalogue_writer:
53-
parent: Translation\Bundle\Catalogue\CatalogueWriter
54-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
55-
public: true
56-
php_translation.catalogue_manager:
57-
parent: Translation\Bundle\Catalogue\CatalogueManager
58-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
59-
public: true
60-
php_translation.extractor:
61-
parent: Translation\Extractor\Extractor
62-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
63-
php_translation.storage_manager:
64-
parent: Translation\Bundle\Service\StorageManager
65-
public: true
66-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
67-
php_translation.configuration_manager:
68-
parent: Translation\Bundle\Service\ConfigurationManager
69-
public: true
70-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
71-
php_translation.importer:
72-
parent: Translation\Bundle\Service\Importer
73-
public: true
74-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
75-
php_translation.cache_clearer:
76-
parent: Translation\Bundle\Service\CacheClearer
77-
public: true
78-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
79-
php_translation.catalogue_counter:
80-
parent: Translation\Bundle\Catalogue\CatalogueCounter
81-
public: true
82-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
83-
php_translation.twig_extension:
84-
parent: Translation\Bundle\Twig\TranslationExtension
85-
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'

0 commit comments

Comments
 (0)