vendor/lexik/jwt-authentication-bundle/DependencyInjection/Security/Factory/JWTUserFactory.php line 41

Open in your IDE?
  1. <?php
  2. namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUser;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUserInterface;
  5. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
  6. use Symfony\Component\Config\Definition\Builder\NodeDefinition;
  7. use Symfony\Component\DependencyInjection\ChildDefinition;
  8. use Symfony\Component\DependencyInjection\ContainerBuilder;
  9. /**
  10.  * Creates the `lexik_jwt` user provider.
  11.  *
  12.  * @internal
  13.  *
  14.  * @author Robin Chalas <[email protected]>
  15.  */
  16. final class JWTUserFactory implements UserProviderFactoryInterface
  17. {
  18.     public function create(ContainerBuilder $container$id$config)
  19.     {
  20.         $container->setDefinition($id, new ChildDefinition('lexik_jwt_authentication.security.jwt_user_provider'))
  21.             ->replaceArgument(0$config['class']);
  22.     }
  23.     public function getKey()
  24.     {
  25.         return 'lexik_jwt';
  26.     }
  27.     public function addConfiguration(NodeDefinition $node)
  28.     {
  29.         $node
  30.             ->children()
  31.                 ->scalarNode('class')
  32.                     ->cannotBeEmpty()
  33.                     ->defaultValue(JWTUser::class)
  34.                     ->validate()
  35.                         ->ifTrue(function ($class) {
  36.                             return !(new \ReflectionClass($class))->implementsInterface(JWTUserInterface::class);
  37.                         })
  38.                         ->thenInvalid('The %s class must implement '.JWTUserInterface::class.' for using the "lexik_jwt" user provider.')
  39.                     ->end()
  40.                 ->end()
  41.             ->end()
  42.         ;
  43.     }
  44. }