<?php
declare(strict_types=1);
namespace League\Bundle\OAuth2ServerBundle;
use League\Bundle\OAuth2ServerBundle\DependencyInjection\CompilerPass\EncryptionKeyPass;
use League\Bundle\OAuth2ServerBundle\DependencyInjection\CompilerPass\RegisterDoctrineOrmMappingPass;
use League\Bundle\OAuth2ServerBundle\DependencyInjection\LeagueOAuth2ServerExtension;
use League\Bundle\OAuth2ServerBundle\DependencyInjection\Security\OAuth2Factory;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class LeagueOAuth2ServerBundle extends Bundle
{
/**
* {@inheritdoc}
*
* @return void
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
$this->configureDoctrineExtension($container);
$this->configureSecurityExtension($container);
}
/**
* {@inheritdoc}
*/
public function getContainerExtension(): ExtensionInterface
{
return new LeagueOAuth2ServerExtension();
}
private function configureSecurityExtension(ContainerBuilder $container): void
{
/** @var SecurityExtension $extension */
$extension = $container->getExtension('security');
if (method_exists($extension, 'addAuthenticatorFactory')) {
$extension->addAuthenticatorFactory(new OAuth2Factory());
return;
}
/**
* @psalm-suppress DeprecatedMethod
* @psalm-suppress InvalidArgument
*/
$extension->addSecurityListenerFactory(new OAuth2Factory());
}
private function configureDoctrineExtension(ContainerBuilder $container): void
{
$container->addCompilerPass(new RegisterDoctrineOrmMappingPass());
$container->addCompilerPass(new EncryptionKeyPass());
}
}