Skip to content

Simplify extractor service configuration #396

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

Closed
wants to merge 4 commits into from
Closed
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
9 changes: 9 additions & 0 deletions DependencyInjection/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class TranslationExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container): void
{
$container->setParameter('extractor_vendor_dir', $this->getExtractorVendorDirectory());

$configuration = new Configuration($container);
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down Expand Up @@ -232,4 +234,11 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co
{
return new Configuration($container);
}

private function getExtractorVendorDirectory(): string
{
$vendorReflection = new \ReflectionClass(FormTypeChoices::class);

return \dirname($vendorReflection->getFileName(), 4);
Copy link
Member

Choose a reason for hiding this comment

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

Won't it be problematic in some edge cases?

For example, if you use a deployment server to warmup the cache before deploying , as the dirname function use the absolute path, it will be problematic if your project is not on the same location on your deployment server & your production server.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason why I used FormTypeChoices is because that class already was in code, and thereby already is loadable. If FormTypeChoices would not be supported anymore in the future, more functionality will break. As the extension only runs on compilation of the container, this will keep working.

Related to the dirname function; Wouldn't the composer autoload then also break? The warmup will lead to a compiled container, so the path only is used to locate the classes in a resource. Afterwards, on runtime the composer autoloader will take over again.

}
}
171 changes: 68 additions & 103 deletions Resources/config/extractors.yaml
Original file line number Diff line number Diff line change
@@ -1,111 +1,76 @@
services:
Translation\Extractor\FileExtractor\PHPFileExtractor:
tags:
- { name: 'php_translation.extractor', type: 'php' }
_defaults:
autowire: true
Copy link
Member

Choose a reason for hiding this comment

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

As discussed in #372 we should not use autowire.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will remove it from the defaults 👍

The bundle currently has 4 occurences of using autowiring, so moving it to the level of the service itself seems ok: https://github.com/php-translation/symfony-bundle/search?q=autowire%3A+true&unscoped_q=autowire%3A+true

bind:
$metadataFactory: '@validator'

Translation\Extractor\FileExtractor\TwigFileExtractor:
arguments: ["@twig"]
tags:
- { name: 'php_translation.extractor', type: 'twig' }
_instanceof:
PhpParser\NodeVisitor:
tags:
- { name: 'php_translation.visitor', type: 'php' }

# PHP Visitors:
Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans:
tags:
- { name: 'php_translation.visitor', type: 'php' }
Translation\Extractor\FileExtractor\PHPFileExtractor:
Copy link
Member

Choose a reason for hiding this comment

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

Could we / should we use the same logic for extractors or does it makes no sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

What logic are you referring to?

tags:
- { name: 'php_translation.extractor', type: 'php' }

Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice:
tags:
- { name: 'php_translation.visitor', type: 'php' }
Translation\Extractor\FileExtractor\TwigFileExtractor:
tags:
- { name: 'php_translation.extractor', type: 'twig' }

Translation\Extractor\Visitor\Php\Symfony\FlashMessage:
tags:
- { name: 'php_translation.visitor', type: 'php' }
# PHP Visitors:
Translation\Extractor\Visitor\Php\Symfony\:
resource: "%extractor_vendor_dir%/Visitor/Php/Symfony/*"

Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices:
tags:
- { name: 'php_translation.visitor', type: 'php' }
Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor: ~

Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue:
tags:
- { name: 'php_translation.visitor', type: 'php' }
# Twig Visitors:
Translation\Extractor\Visitor\Twig\TwigVisitor:
tags:
- { name: 'php_translation.visitor', type: 'twig' }

Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp:
tags:
- { name: 'php_translation.visitor', type: 'php' }

Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage:
tags:
- { name: 'php_translation.visitor', type: 'php' }

Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit:
tags:
- { name: 'php_translation.visitor', type: 'php' }

Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit:
tags:
- { name: 'php_translation.visitor', type: 'php' }

Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder:
tags:
- { name: 'php_translation.visitor', type: 'php' }

Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation:
arguments: ['@validator']
tags:
- { name: 'php_translation.visitor', type: 'php' }

Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor:
tags:
- { name: 'php_translation.visitor', type: 'php' }

# Twig Visitors:
Translation\Extractor\Visitor\Twig\TwigVisitor:
tags:
- { name: 'php_translation.visitor', type: 'twig' }

# To remove in next major release
php_translation.extractor.php:
parent: Translation\Extractor\FileExtractor\PHPFileExtractor
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.twig:
parent: Translation\Extractor\FileExtractor\TwigFileExtractor
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.ContainerAwareTrans:
parent: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.ContainerAwareTransChoice:
parent: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FlashMessage:
parent: Translation\Extractor\Visitor\Php\Symfony\FlashMessage
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeChoices:
parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeEmptyValue:
parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeHelp:
parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeInvalidMessage:
parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeLabelExplicit:
parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeLabelImplicit:
parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypePlaceholder:
parent: Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.ValidationAnnotation:
parent: Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.php.visitor.SourceLocationContainerVisitor:
parent: Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
php_translation.extractor.twig.factory.twig:
parent: Translation\Extractor\Visitor\Twig\TwigVisitor
deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'
# To remove in next major release
php_translation.extractor.php:
alias: Translation\Extractor\FileExtractor\PHPFileExtractor
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.twig:
alias: Translation\Extractor\FileExtractor\TwigFileExtractor
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.ContainerAwareTrans:
alias: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.ContainerAwareTransChoice:
alias: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FlashMessage:
alias: Translation\Extractor\Visitor\Php\Symfony\FlashMessage
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeChoices:
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeEmptyValue:
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeHelp:
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeInvalidMessage:
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeLabelExplicit:
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypeLabelImplicit:
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.FormTypePlaceholder:
alias: Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.ValidationAnnotation:
alias: Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.php.visitor.SourceLocationContainerVisitor:
alias: Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
php_translation.extractor.twig.factory.twig:
alias: Translation\Extractor\Visitor\Twig\TwigVisitor
deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.'
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ parameters:
count: 1
path: Command/StatusCommand.php

-
message: "#^Call to method getValue\\(\\) on an unknown class Symfony\\\\Component\\\\Translation\\\\DataCollector\\\\Data\\.$#"
count: 1
path: Controller/SymfonyProfilerController.php

-
message: "#^Call to an undefined static method Symfony\\\\Component\\\\Intl\\\\Intl\\:\\:getLocaleBundle\\(\\)\\.$#"
count: 1
Expand Down