vendor/sonata-project/user-bundle/src/SonataUserBundle.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\UserBundle;
  12. use Sonata\CoreBundle\Form\FormHelper;
  13. use Sonata\UserBundle\DependencyInjection\Compiler\GlobalVariablesCompilerPass;
  14. use Sonata\UserBundle\DependencyInjection\Compiler\RolesMatrixCompilerPass;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\HttpKernel\Bundle\Bundle;
  17. class SonataUserBundle extends Bundle
  18. {
  19.     public function build(ContainerBuilder $container): void
  20.     {
  21.         $container->addCompilerPass(new GlobalVariablesCompilerPass());
  22.         $container->addCompilerPass(new RolesMatrixCompilerPass());
  23.         $this->registerFormMapping();
  24.     }
  25.     public function boot(): void
  26.     {
  27.         $this->registerFormMapping();
  28.         $this->createDoctrineCommonBackwardCompatibilityAliases();
  29.     }
  30.     /**
  31.      * Register form mapping information.
  32.      *
  33.      * NEXT_MAJOR: remove this method
  34.      */
  35.     public function registerFormMapping(): void
  36.     {
  37.         if (class_exists(FormHelper::class)) {
  38.             FormHelper::registerFormTypeMapping([
  39.                 'fos_user_username' => 'FOS\UserBundle\Form\Type\UsernameFormType',
  40.                 'fos_user_profile' => 'FOS\UserBundle\Form\Type\ProfileFormType',
  41.                 'fos_user_registration' => 'FOS\UserBundle\Form\Type\RegistrationFormType',
  42.                 'fos_user_change_password' => 'FOS\UserBundle\Form\Type\ChangePasswordFormType',
  43.                 'fos_user_resetting' => 'FOS\UserBundle\Form\Type\ResettingFormType',
  44.                 'fos_user_group' => 'FOS\UserBundle\Form\Type\GroupFormType',
  45.                 'sonata_security_roles' => 'Sonata\UserBundle\Form\Type\SecurityRolesType',
  46.                 'sonata_user_profile' => 'Sonata\UserBundle\Form\Type\ProfileType',
  47.                 'sonata_user_gender' => 'Sonata\UserBundle\Form\Type\UserGenderListType',
  48.                 'sonata_user_registration' => 'Sonata\UserBundle\Form\Type\RegistrationFormType',
  49.                 'sonata_user_api_form_group' => 'Sonata\UserBundle\Form\Type\ApiGroupType',
  50.                 'sonata_user_api_form_user' => 'Sonata\UserBundle\Form\Type\ApiUserType',
  51.             ]);
  52.         }
  53.     }
  54.     /**
  55.      * We MUST remove this method when support for "friendsofsymfony/user-bundle" is dropped
  56.      * or adapted to work with "doctrine/common:^3".
  57.      */
  58.     private function createDoctrineCommonBackwardCompatibilityAliases(): void
  59.     {
  60.         if (!interface_exists(\Doctrine\Common\Persistence\ObjectManager::class)) {
  61.             class_alias(\Doctrine\Persistence\ObjectManager::class, \Doctrine\Common\Persistence\ObjectManager::class);
  62.         }
  63.         if (!class_exists(\Doctrine\Common\Persistence\Event\LifecycleEventArgs::class)) {
  64.             class_alias(\Doctrine\Persistence\Event\LifecycleEventArgs::class, \Doctrine\Common\Persistence\Event\LifecycleEventArgs::class);
  65.         }
  66.     }
  67. }