File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33declare (strict_types=1 );
44
5+ use MsgPhp \User \Repository \UserRepositoryInterface ;
56use MsgPhp \UserBundle \Twig ;
67use 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
812return 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};
Original file line number Diff line number Diff line change 99use MsgPhp \User \Repository \UserRepositoryInterface ;
1010use MsgPhp \User \UserIdInterface ;
1111use Psr \Container \ContainerInterface ;
12- use Symfony \Component \DependencyInjection \ServiceSubscriberInterface ;
1312use 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)) {
You can’t perform that action at this time.
0 commit comments