vendor/league/oauth2-server-bundle/src/LeagueOAuth2ServerBundle.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace League\Bundle\OAuth2ServerBundle;
  4. use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
  5. use League\Bundle\OAuth2ServerBundle\DependencyInjection\CompilerPass\EncryptionKeyPass;
  6. use League\Bundle\OAuth2ServerBundle\DependencyInjection\LeagueOAuth2ServerExtension;
  7. use League\Bundle\OAuth2ServerBundle\DependencyInjection\Security\OAuth2Factory;
  8. use League\Bundle\OAuth2ServerBundle\Persistence\Mapping\Driver;
  9. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  10. use Symfony\Component\DependencyInjection\ContainerBuilder;
  11. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  12. use Symfony\Component\DependencyInjection\Reference;
  13. use Symfony\Component\HttpKernel\Bundle\Bundle;
  14. final class LeagueOAuth2ServerBundle extends Bundle
  15. {
  16.     /**
  17.      * @return void
  18.      */
  19.     public function build(ContainerBuilder $container)
  20.     {
  21.         parent::build($container);
  22.         $this->configureDoctrineExtension($container);
  23.         $this->configureSecurityExtension($container);
  24.     }
  25.     public function getContainerExtension(): ExtensionInterface
  26.     {
  27.         return new LeagueOAuth2ServerExtension();
  28.     }
  29.     /**
  30.      * @psalm-suppress UndefinedMethod
  31.      */
  32.     private function configureSecurityExtension(ContainerBuilder $container): void
  33.     {
  34.         /** @var SecurityExtension $extension */
  35.         $extension $container->getExtension('security');
  36.         if (method_exists($extension'addAuthenticatorFactory')) {
  37.             $extension->addAuthenticatorFactory(new OAuth2Factory());
  38.             return;
  39.         }
  40.         /**
  41.          * @psalm-suppress DeprecatedMethod
  42.          * @psalm-suppress InvalidArgument
  43.          */
  44.         $extension->addSecurityListenerFactory(new OAuth2Factory());
  45.     }
  46.     private function configureDoctrineExtension(ContainerBuilder $container): void
  47.     {
  48.         $container->addCompilerPass(
  49.             new DoctrineOrmMappingsPass(
  50.                 new Reference(Driver::class),
  51.                 ['League\Bundle\OAuth2ServerBundle\Model'],
  52.                 ['league.oauth2_server.persistence.doctrine.manager'],
  53.                 'league.oauth2_server.persistence.doctrine.enabled'
  54.             )
  55.         );
  56.         $container->addCompilerPass(new EncryptionKeyPass());
  57.     }
  58. }