Skip to content

Commit 0ae3564

Browse files
fix(137): change FQN class in services.xml
change FQN class in services + bind argument GetLabel to TwigExtension + rename id of the service + tweak tests + update docs. Fixes #137
1 parent ccd86f4 commit 0ae3564

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ the `GetLabel` class and invoke it.
157157
use Greg0ire\Enum\Bridge\Symfony\Translator\GetLabel;
158158

159159
$label = new GetLabel();
160-
$label($value, 'Your\Enum\Class');
160+
$label(Your\Enum\Class::VALUE, Your\Enum\Class::class);
161161
```
162162

163163
To enable translation, require the `symfony/translation` component
@@ -169,26 +169,26 @@ use Greg0ire\Enum\Bridge\Symfony\Translator\GetLabel;
169169
use Symfony\Contracts\Translation\TranslationInterface;
170170

171171
$label = new GetLabel($translator);
172-
$label($value, 'Your\Enum\Class');
172+
$label(Your\Enum\Class::VALUE, Your\Enum\Class::class);
173173
```
174174

175-
If you're using Symfony, tag the service and simply inject it.
175+
If you're using Symfony, alias the service and simply inject it.
176176
If translations are enabled, the `TranslatorInterface` will be automatically injected.
177177

178178
```yaml
179179
services:
180180
# ...
181-
Greg0ire\Enum\Bridge\Symfony\Translator\Label: "@greg0ire_enum.symfony.translator.label"
181+
Greg0ire\Enum\Bridge\Symfony\Translator\GetLabel: "@greg0ire_enum.symfony.translator.get_label"
182182
```
183183
184184
```php
185185
public function index(GetLabel $label)
186186
{
187-
$label($value, 'Your\Enum\Class');
188-
$label($value, 'Your\Enum\Class', 'another_domain'); // Change the translation domain
189-
$label($value, 'Your\Enum\Class', false); // Disable translation. In this case the class prefix wont be added
190-
$label($value, 'Your\Enum\Class', false, true); // Disable translation but keep class prefix
191-
$label($value, 'Your\Enum\Class', false, true, '.'); // Disable translation but keep class prefix with a custom separator
187+
$label(Your\Enum\Class::VALUE, Your\Enum\Class::class);
188+
$label(Your\Enum\Class::VALUE, Your\Enum\Class::class, 'another_domain'); // Change the translation domain
189+
$label(Your\Enum\Class::VALUE, Your\Enum\Class::class, false); // Disable translation. In this case the class prefix wont be added
190+
$label(Your\Enum\Class::VALUE, Your\Enum\Class::class, false, true); // Disable translation but keep class prefix
191+
$label(Your\Enum\Class::VALUE, Your\Enum\Class::class, false, true, '.'); // Disable translation but keep class prefix with a custom separator
192192
}
193193
```
194194

src/Bridge/Symfony/DependencyInjection/Compiler/TranslatorCompilerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class TranslatorCompilerPass implements CompilerPassInterface
1818
public function process(ContainerBuilder $container): void
1919
{
2020
if (class_exists(AbstractExtension::class) && $container->hasDefinition('translator.default')) {
21-
$container->getDefinition('greg0ire_enum.symfony.translator.label')
21+
$container->getDefinition('greg0ire_enum.symfony.translator.get_label')
2222
->addArgument(new Reference('translator.default'));
2323
}
2424
}

src/Bridge/Symfony/Resources/config/services.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<services>
77
<defaults public="false" />
88

9-
<service id="greg0ire_enum.symfony.translator.label" class="Greg0ire\Enum\Bridge\Symfony\Translator\Label" public="true">
9+
<service id="greg0ire_enum.symfony.translator.get_label" class="Greg0ire\Enum\Bridge\Symfony\Translator\GetLabel" public="true">
1010
<argument type="service" id="translator.default" />
1111
</service>
1212

src/Bridge/Symfony/Resources/config/twig.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<services>
77
<service id="greg0ire_enum.twig.extension.enum" class="Greg0ire\Enum\Bridge\Twig\Extension\EnumExtension">
88
<tag name="twig.extension"/>
9+
<argument type="service" id="greg0ire_enum.symfony.translator.get_label" />
910
</service>
1011
</services>
1112
</container>

tests/Bridge/Symfony/DependencyInjection/Greg0ireEnumExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testLabelServiceHasTheTranslator()
7474
$compilerPass->process($this->container);
7575

7676
$this->assertContainerBuilderHasServiceDefinitionWithArgument(
77-
'greg0ire_enum.symfony.translator.label',
77+
'greg0ire_enum.symfony.translator.get_label',
7878
0,
7979
new Reference('translator.default')
8080
);

0 commit comments

Comments
 (0)