Skip to content

Commit 5d42441

Browse files
committed
Let's do some black magic to retrieve the correct provider instance at compile time.
1 parent 4a6f5b9 commit 5d42441

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

DependencyInjection/GraphqliteCompilerPass.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public function process(ContainerBuilder $container)
8686
$controllersNamespaces = $container->getParameter('graphqlite.namespace.controllers');
8787
$typesNamespaces = $container->getParameter('graphqlite.namespace.types');
8888

89+
$firewallName = $container->getParameter('graphqlite.security.firewall_name');
90+
$firewallConfigServiceName = 'security.firewall.map.config.'.$firewallName;
91+
8992
// 2 seconds of TTL in environment mode. Otherwise, let's cache forever!
9093

9194
$schemaFactory = $container->getDefinition(SchemaFactory::class);
@@ -99,7 +102,7 @@ public function process(ContainerBuilder $container)
99102

100103
$disableLogin = false;
101104
if ($container->getParameter('graphqlite.security.enable_login') === 'auto'
102-
&& (!$container->has(UserProviderInterface::class) ||
105+
&& (!$container->has($firewallConfigServiceName) ||
103106
!$container->has(UserPasswordEncoderInterface::class) ||
104107
!$container->has(TokenStorageInterface::class) ||
105108
!$container->has(SessionInterface::class)
@@ -119,11 +122,18 @@ public function process(ContainerBuilder $container)
119122
if (!$container->has(SessionInterface::class)) {
120123
throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to enable session support (via the "framework.session.enabled" config parameter).');
121124
}
122-
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has(UserProviderInterface::class)) {
125+
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has($firewallConfigServiceName)) {
123126
throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to install the security bundle. Please be sure to correctly configure the user provider (in the security.providers configuration settings)');
124127
}
125128
}
126129

130+
if ($disableLogin === false) {
131+
// Let's do some dark magic. We need the user provider. We need its name. It is stored in the "config" object.
132+
$provider = $container->findDefinition('security.firewall.map.config.'.$firewallName)->getArgument(5);
133+
134+
$container->findDefinition(LoginController::class)->setArgument(0, new Reference($provider));
135+
}
136+
127137

128138
foreach ($container->getDefinitions() as $id => $definition) {
129139
if ($definition->isAbstract() || $definition->getClass() === null) {

0 commit comments

Comments
 (0)