Skip to content
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

register new interface for translator #81

Merged
merged 2 commits into from
Aug 4, 2024
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"laminas/laminas-inputfilter": "^2.12",
"bnf/phpstan-psr-container": "^1.0",
"symplify/easy-coding-standard": "^12.0",
"doctrine/annotations": "^2.0"
"doctrine/annotations": "^2.0",
"laminas/laminas-translator": "^1.0"
},
"extra": {
"zf": {
Expand Down
2 changes: 0 additions & 2 deletions src/AbstractFactory/FallbackAutoWiringFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Reinfi\DependencyInjection\Factory\AutoWiringFactory;

/**
* Class FallbackAutoWiringFactory
*
* Note: Please DO NOT use this factory for everything.
* If you're implementing new classes, please write a concrete factory.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Injection/InjectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Psr\Container\ContainerInterface;

/**
* Interface InjectionInterface
*
* @package Reinfi\DependencyInjection\Injection
*/
interface InjectionInterface
Expand Down
20 changes: 16 additions & 4 deletions src/Service/AutoWiring/Resolver/TranslatorResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@
class TranslatorResolver implements ResolverInterface
{
/**
* used to avoid requirement of laminas/laminas-i18n module
* used to avoid requirement of laminas/laminas-i18n module, deprecated interface name.
*/
private const TRANSLATOR_INTERFACE = 'Laminas\I18n\Translator\TranslatorInterface';
private const TRANSLATOR_INTERFACE_OLD = 'Laminas\I18n\Translator\TranslatorInterface';

/**
* used to avoid requirement of laminas/laminas-translator module.
*/
private const TRANSLATOR_INTERFACE = 'Laminas\Translator\TranslatorInterface';

/**
* possible names for translator service within container
*/
private const TRANSLATOR_CONTAINER_SERVICE_NAME = ['MvcTranslator', self::TRANSLATOR_INTERFACE, 'Translator'];
private const TRANSLATOR_CONTAINER_SERVICE_NAME = [
self::TRANSLATOR_INTERFACE,
'MvcTranslator',
self::TRANSLATOR_INTERFACE_OLD,
'Translator',
];

private ContainerInterface $container;

Expand Down Expand Up @@ -65,7 +75,9 @@ private function isValid(ReflectionParameter $parameter): bool
$reflectionClass = new ReflectionClass($type->getName());
$interfaceNames = $reflectionClass->getInterfaceNames();

return $reflectionClass->getName() === self::TRANSLATOR_INTERFACE
return $reflectionClass->getName() === self::TRANSLATOR_INTERFACE_OLD
|| in_array(self::TRANSLATOR_INTERFACE_OLD, $interfaceNames, true)
|| $reflectionClass->getName() === self::TRANSLATOR_INTERFACE
|| in_array(self::TRANSLATOR_INTERFACE, $interfaceNames, true)
;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Service/Extractor/ExtractorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Reinfi\DependencyInjection\Injection\InjectionInterface;

/**
* Interface ExtractorInterface
*
* @package Reinfi\DependencyInjection\Service\Extractor
*/
interface ExtractorInterface
Expand Down
2 changes: 0 additions & 2 deletions src/Traits/CacheKeyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Reinfi\DependencyInjection\Config\ModuleConfig;

/**
* Trait CacheKeyTrait
*
* @package Reinfi\DependencyInjection\Traits
*/
trait CacheKeyTrait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function testItReturnsNullIfNoTranslatorRegistered(): void

$container->has('MvcTranslator')->willReturn(false);
$container->has(TranslatorInterface::class)->willReturn(false);
$container->has(\Laminas\Translator\TranslatorInterface::class)->willReturn(false);
$container->has('Translator')->willReturn(false);

$resolver = new TranslatorResolver($container->reveal());
Expand Down Expand Up @@ -141,17 +142,25 @@ public static function containerHasCallsProvider(): array
return [
[
[
'Laminas\Translator\TranslatorInterface' => true,
],
],
[
[
'Laminas\Translator\TranslatorInterface' => false,
'MvcTranslator' => true,
],
],
[
[
'Laminas\Translator\TranslatorInterface' => false,
'MvcTranslator' => false,
'Laminas\I18n\Translator\TranslatorInterface' => true,
],
],
[
[
'Laminas\Translator\TranslatorInterface' => false,
'MvcTranslator' => false,
'Laminas\I18n\Translator\TranslatorInterface' => false,
'Translator' => true,
Expand Down
Loading