Skip to content

Commit ff4541d

Browse files
committed
fix sf/di deprecation
1 parent 922a5a4 commit ff4541d

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

‎src/UserBundle/Resources/config/twig.php‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
declare(strict_types=1);
44

5+
use MsgPhp\User\Repository\UserRepositoryInterface;
56
use MsgPhp\UserBundle\Twig;
67
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
use Symfony\Component\DependencyInjection\ServiceLocator;
9+
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
10+
use function Symfony\Component\DependencyInjection\Loader\Configurator\{inline, ref};
711

812
return function (ContainerConfigurator $container): void {
913
$container->services()
1014
->defaults()
11-
->autowire()
12-
->autoconfigure()
1315
->private()
1416

1517
->set(Twig\GlobalVariable::class)
18+
->args([
19+
inline(ServiceLocator::class)
20+
->args([[
21+
TokenStorageInterface::class => ref(TokenStorageInterface::class)->nullOnInvalid(),
22+
UserRepositoryInterface::class => ref(UserRepositoryInterface::class)->nullOnInvalid(),
23+
]])
24+
->tag('container.service_locator'),
25+
])
1626
;
1727
};

‎src/UserBundle/Twig/GlobalVariable.php‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
use MsgPhp\User\Repository\UserRepositoryInterface;
1010
use MsgPhp\User\UserIdInterface;
1111
use Psr\Container\ContainerInterface;
12-
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
1312
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1413

1514
/**
1615
* @author Roland Franssen <franssen.roland@gmail.com>
1716
*
1817
* @internal
1918
*/
20-
final class GlobalVariable implements ServiceSubscriberInterface
19+
final class GlobalVariable
2120
{
2221
public const NAME = 'msgphp_user';
2322

@@ -55,14 +54,6 @@ public function isUserType(User $user, string $class): bool
5554
return $user instanceof $class;
5655
}
5756

58-
public static function getSubscribedServices(): array
59-
{
60-
return [
61-
'?'.TokenStorageInterface::class,
62-
'?'.UserRepositoryInterface::class,
63-
];
64-
}
65-
6657
private function getTokenStorage(): TokenStorageInterface
6758
{
6859
if (!$this->container->has(TokenStorageInterface::class)) {

0 commit comments

Comments
 (0)