mrvendor/sonata-project/media-bundle/src/SonataMediaBundle.php line 33

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\MediaBundle;
  12. use Sonata\CoreBundle\Form\FormHelper;
  13. use Sonata\MediaBundle\DependencyInjection\Compiler\AddProviderCompilerPass;
  14. use Sonata\MediaBundle\DependencyInjection\Compiler\GlobalVariablesCompilerPass;
  15. use Sonata\MediaBundle\DependencyInjection\Compiler\ThumbnailCompilerPass;
  16. use Sonata\MediaBundle\DependencyInjection\Compiler\TwigStringExtensionCompilerPass;
  17. use Sonata\MediaBundle\Form\Type\ApiDoctrineMediaType;
  18. use Sonata\MediaBundle\Form\Type\ApiGalleryHasMediaType;
  19. use Sonata\MediaBundle\Form\Type\ApiGalleryType;
  20. use Sonata\MediaBundle\Form\Type\ApiMediaType;
  21. use Sonata\MediaBundle\Form\Type\MediaType;
  22. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  23. use Symfony\Component\DependencyInjection\ContainerBuilder;
  24. use Symfony\Component\HttpKernel\Bundle\Bundle;
  25. /**
  26.  * @final since sonata-project/media-bundle 3.21.0
  27.  */
  28. class SonataMediaBundle extends Bundle
  29. {
  30.     public function build(ContainerBuilder $container)
  31.     {
  32.         $container->addCompilerPass(new AddProviderCompilerPass());
  33.         $container->addCompilerPass(new GlobalVariablesCompilerPass());
  34.         $container->addCompilerPass(new ThumbnailCompilerPass());
  35.         $container->addCompilerPass(new TwigStringExtensionCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION1);
  36.         $this->registerFormMapping();
  37.     }
  38.     public function boot()
  39.     {
  40.         // this is required by the AWS SDK (see: https://github.com/knplabs/Gaufrette)
  41.         if (!\defined('AWS_CERTIFICATE_AUTHORITY')) {
  42.             \define('AWS_CERTIFICATE_AUTHORITY'true);
  43.         }
  44.         $this->registerFormMapping();
  45.     }
  46.     /**
  47.      * Register form mapping information.
  48.      *
  49.      * NEXT_MAJOR: remove this method
  50.      */
  51.     public function registerFormMapping()
  52.     {
  53.         if (class_exists(FormHelper::class)) {
  54.             FormHelper::registerFormTypeMapping([
  55.                 'sonata_media_type' => MediaType::class,
  56.                 'sonata_media_api_form_media' => ApiMediaType::class,
  57.                 'sonata_media_api_form_doctrine_media' => ApiDoctrineMediaType::class,
  58.                 'sonata_media_api_form_gallery' => ApiGalleryType::class,
  59.                 'sonata_media_api_form_gallery_has_media' => ApiGalleryHasMediaType::class,
  60.             ]);
  61.         }
  62.     }
  63. }