Skip to content

Deprecate a bunch of service aliases #368

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

Merged
merged 1 commit into from
Dec 26, 2019
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
8 changes: 3 additions & 5 deletions DependencyInjection/CompilerPass/EditInPlacePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Translation\Bundle\Translator\EditInPlaceTranslator;

/**
* @author Damien Alexandre <dalexandre@jolicode.com>
Expand All @@ -24,14 +25,11 @@ class EditInPlacePass implements CompilerPassInterface
public function process(ContainerBuilder $container): void
{
/* @var Definition $def */
if (!$container->hasDefinition('php_translator.edit_in_place.xtrans_html_translator')) {
if (!$container->hasDefinition(EditInPlaceTranslator::class)) {
return;
}

// Replace the Twig Translator by a custom HTML one
$container->getDefinition('twig.extension.trans')->replaceArgument(
0,
new Reference('php_translator.edit_in_place.xtrans_html_translator')
);
$container->getDefinition('twig.extension.trans')->replaceArgument(0, new Reference(EditInPlaceTranslator::class));
}
}
5 changes: 3 additions & 2 deletions DependencyInjection/CompilerPass/ExtractorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Translation\Extractor\Extractor;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
Expand All @@ -32,12 +33,12 @@ public function process(ContainerBuilder $container): void
*/
private function getExtractors(ContainerBuilder $container): array
{
if (!$container->hasDefinition('php_translation.extractor')) {
if (!$container->hasDefinition(Extractor::class)) {
return [];
}

/** @var Definition $def */
$def = $container->getDefinition('php_translation.extractor');
$def = $container->getDefinition(Extractor::class);
$services = $container->findTaggedServiceIds('php_translation.extractor');
$extractors = [];
foreach ($services as $id => $tags) {
Expand Down
3 changes: 2 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Translation\Bundle\EditInPlace\Activator;

/**
* This is the class that validates and merges configuration from your app/config files.
Expand Down Expand Up @@ -199,7 +200,7 @@ private function addEditInPlaceNode(ArrayNodeDefinition $root): void
->canBeEnabled()
->children()
->scalarNode('config_name')->defaultValue('default')->end()
->scalarNode('activator')->cannotBeEmpty()->defaultValue('php_translation.edit_in_place.activator')->end()
->scalarNode('activator')->cannotBeEmpty()->defaultValue(Activator::class)->end()
->scalarNode('show_untranslatable')->defaultTrue()->end()
->end()
->end()
Expand Down
25 changes: 14 additions & 11 deletions DependencyInjection/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;
use Translation\Bundle\EventListener\AutoAddMissingTranslations;
use Translation\Bundle\EventListener\EditInPlaceResponseListener;
use Translation\Bundle\Model\Configuration as ConfigurationModel;
use Translation\Bundle\Service\ConfigurationManager;
use Translation\Bundle\Service\StorageManager;
use Translation\Bundle\Service\StorageService;
use Translation\Bundle\Translator\EditInPlaceTranslator;
use Translation\Bundle\Twig\EditInPlaceExtension;
use Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices;

/**
* This is the class that loads and manages your bundle configuration.
Expand All @@ -43,7 +50,7 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('extractors.yaml');

// Add major version to extractor
$container->getDefinition('php_translation.extractor.php.visitor.FormTypeChoices')
$container->getDefinition(FormTypeChoices::class)
->addMethodCall('setSymfonyMajorVersion', [Kernel::MAJOR_VERSION]);

$container->setParameter('php_translation.locales', $config['locales']);
Expand All @@ -70,7 +77,7 @@ public function load(array $configs, ContainerBuilder $container): void

if ($config['auto_add_missing_translations']['enabled']) {
$loader->load('auto_add.yaml');
$container->getDefinition('php_translator.auto_adder')
$container->getDefinition(AutoAddMissingTranslations::class)
->replaceArgument(0, new Reference('php_translation.storage.'.$config['auto_add_missing_translations']['config_name']));
}

Expand All @@ -79,10 +86,6 @@ public function load(array $configs, ContainerBuilder $container): void
$this->enableFallbackAutoTranslator($container, $config);
}

if ('test' === \getenv('ENV')) {
$loader->load('services_test.yaml');
}

$loader->load('console.yaml');
}

Expand All @@ -91,8 +94,8 @@ public function load(array $configs, ContainerBuilder $container): void
*/
private function handleConfigNode(ContainerBuilder $container, array $config): void
{
$storageManager = $container->getDefinition('php_translation.storage_manager');
$configurationManager = $container->getDefinition('php_translation.configuration_manager');
$storageManager = $container->getDefinition(StorageManager::class);
$configurationManager = $container->getDefinition(ConfigurationManager::class);
// $first will be the "default" configuration.
$first = null;
foreach ($config['configs'] as $name => &$c) {
Expand Down Expand Up @@ -179,15 +182,15 @@ private function enableEditInPlace(ContainerBuilder $container, array $config):

$activatorRef = new Reference($config['edit_in_place']['activator']);

$def = $container->getDefinition('php_translation.edit_in_place.response_listener');
$def = $container->getDefinition(EditInPlaceResponseListener::class);
$def->replaceArgument(0, $activatorRef);
$def->replaceArgument(3, $name);
$def->replaceArgument(4, $config['edit_in_place']['show_untranslatable']);

$def = $container->getDefinition('php_translator.edit_in_place.xtrans_html_translator');
$def = $container->getDefinition(EditInPlaceTranslator::class);
$def->replaceArgument(1, $activatorRef);

$def = $container->getDefinition('php_translation.edit_in_place.extension.trans');
$def = $container->getDefinition(EditInPlaceExtension::class);
$def->replaceArgument(2, $activatorRef);
}

Expand Down
3 changes: 1 addition & 2 deletions Resources/config/auto_add.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
services:
php_translator.auto_adder:
class: Translation\Bundle\EventListener\AutoAddMissingTranslations
Translation\Bundle\EventListener\AutoAddMissingTranslations:
arguments: [ ~, '@?translator.data_collector' ]
tags:
- { name: kernel.event_listener, event: kernel.terminate, method: onTerminate, priority: 10 }
3 changes: 1 addition & 2 deletions Resources/config/auto_translation.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
services:
php_translator.fallback_translator:
class: Translation\Bundle\Translator\FallbackTranslator
Translation\Bundle\Translator\FallbackTranslator:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed php_translator.fallback_translator in adding a deprecated alias.

php_translator.fallback_translator:
	alias:  Translation\Bundle\Translator\FallbackTranslator
	deprecated: ~

public: false
decorates: 'translator'
decoration_priority: 10
Expand Down
64 changes: 38 additions & 26 deletions Resources/config/console.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
services:
php_translator.console.delete_obsolete:
class: Translation\Bundle\Command\DeleteObsoleteCommand
Translation\Bundle\Command\DeleteObsoleteCommand:
public: true
arguments:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about removing all arguments definitions, and:

_defaults:
	autowire: true

- '@php_translation.storage_manager'
- '@php_translation.configuration_manager'
- '@php_translation.catalogue_manager'
- '@php_translation.catalogue_fetcher'
- '@Translation\Bundle\Service\StorageManager'
- '@Translation\Bundle\Service\ConfigurationManager'
- '@Translation\Bundle\Catalogue\CatalogueManager'
- '@Translation\Bundle\Catalogue\CatalogueFetcher'
tags:
- { name: console.command, command: translation:delete-obsolete}

php_translator.console.download:
class: Translation\Bundle\Command\DownloadCommand
Translation\Bundle\Command\DownloadCommand:
public: true
arguments:
- '@php_translation.storage_manager'
- '@php_translation.configuration_manager'
- '@php_translation.cache_clearer'
- '@Translation\Bundle\Service\StorageManager'
- '@Translation\Bundle\Service\ConfigurationManager'
- '@Translation\Bundle\Service\CacheClearer'
tags:
- { name: console.command, command: translation:download }

php_translator.console.extract:
class: Translation\Bundle\Command\ExtractCommand
Translation\Bundle\Command\ExtractCommand:
public: true
arguments:
- '@php_translation.catalogue_fetcher'
- '@php_translation.catalogue_writer'
- '@php_translation.catalogue_counter'
- '@php_translation.importer'
- '@php_translation.configuration_manager'
- '@Translation\Bundle\Catalogue\CatalogueFetcher'
- '@Translation\Bundle\Catalogue\CatalogueWriter'
- '@Translation\Bundle\Catalogue\CatalogueCounter'
- '@Translation\Bundle\Service\Importer'
- '@Translation\Bundle\Service\ConfigurationManager'
tags:
- { name: console.command, command: translation:extract }

php_translator.console.status:
class: Translation\Bundle\Command\StatusCommand
Translation\Bundle\Command\StatusCommand:
public: true
arguments:
- '@php_translation.catalogue_counter'
- '@php_translation.configuration_manager'
- '@php_translation.catalogue_fetcher'
- '@Translation\Bundle\Catalogue\CatalogueCounter'
- '@Translation\Bundle\Service\ConfigurationManager'
- '@Translation\Bundle\Catalogue\CatalogueFetcher'
tags:
- { name: console.command, command: translation:status }

php_translator.console.sync:
class: Translation\Bundle\Command\SyncCommand
Translation\Bundle\Command\SyncCommand:
public: true
arguments:
- '@php_translation.storage_manager'
- '@Translation\Bundle\Service\StorageManager'
tags:
- { name: console.command, command: translation:sync }

# To remove in next major release
php_translator.console.delete_obsolete:
parent: Translation\Bundle\Command\DeleteObsoleteCommand
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translator.console.download:
parent: Translation\Bundle\Command\DownloadCommand
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translator.console.extract:
parent: Translation\Bundle\Command\ExtractCommand
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translator.console.status:
parent: Translation\Bundle\Command\StatusCommand
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translator.console.sync:
parent: Translation\Bundle\Command\SyncCommand
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
26 changes: 18 additions & 8 deletions Resources/config/edit_in_place.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ services:
- '@Translation\Bundle\Service\CacheClearer'
- '@Symfony\Component\Validator\Validator\ValidatorInterface'

php_translation.edit_in_place.response_listener:
class: Translation\Bundle\EventListener\EditInPlaceResponseListener
Translation\Bundle\EventListener\EditInPlaceResponseListener:
tags:
- { name: 'kernel.event_listener', event: 'kernel.response', method: 'onKernelResponse' }
arguments:
Expand All @@ -19,24 +18,35 @@ services:
- ~
- ~

php_translation.edit_in_place.activator:
class: Translation\Bundle\EditInPlace\Activator
Translation\Bundle\EditInPlace\Activator:
arguments: ['@session']
public: true

php_translator.edit_in_place.xtrans_html_translator:
class: Translation\Bundle\Translator\EditInPlaceTranslator
Translation\Bundle\Translator\EditInPlaceTranslator:
arguments:
- '@translator'
- ~
- '@request_stack'

php_translation.edit_in_place.extension.trans:
Translation\Bundle\Twig\EditInPlaceExtension:
public: false
class: Translation\Bundle\Twig\EditInPlaceExtension
arguments:
- '@twig.extension.trans'
- '@request_stack'
- ~
tags:
- { name: 'twig.extension' }

# To remove in next major release
php_translation.edit_in_place.response_listener:
parent: Translation\Bundle\EventListener\EditInPlaceResponseListener
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.edit_in_place.activator:
parent: Translation\Bundle\EditInPlace\Activator
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translator.edit_in_place.xtrans_html_translator:
parent: Translation\Bundle\Translator\EditInPlaceTranslator
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.edit_in_place.extension.trans:
parent: Translation\Bundle\Twig\EditInPlaceExtension
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
Loading