vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/SyliusCoreBundle.php line 41

  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\CoreBundle;
  12. use Doctrine\Inflector\InflectorFactory;
  13. use Doctrine\Inflector\Rules\Patterns;
  14. use Doctrine\Inflector\Rules\Ruleset;
  15. use Doctrine\Inflector\Rules\Substitution;
  16. use Doctrine\Inflector\Rules\Substitutions;
  17. use Doctrine\Inflector\Rules\Transformations;
  18. use Doctrine\Inflector\Rules\Word;
  19. use Doctrine\ORM\Query;
  20. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\BackwardsCompatibility\CancelOrderStateMachineCallbackPass;
  21. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\BackwardsCompatibility\ResolveShopUserTargetEntityPass;
  22. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\BackwardsCompatibility\Symfony5AuthenticationManagerPass;
  23. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\BackwardsCompatibility\Symfony6PrivateServicesPass;
  24. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\CircularDependencyBreakingErrorListenerPass;
  25. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\IgnoreAnnotationsPass;
  26. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\LazyCacheWarmupPass;
  27. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\LiipImageFiltersPass;
  28. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterTaxCalculationStrategiesPass;
  29. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterUriBasedSectionResolverPass;
  30. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\TranslatableEntityLocalePass;
  31. use Sylius\Bundle\CoreBundle\Doctrine\ORM\SqlWalker\OrderByIdentifierSqlWalker;
  32. use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
  33. use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
  34. use Sylius\Component\Resource\Metadata\Metadata;
  35. use Symfony\Component\DependencyInjection\ContainerBuilder;
  36. final class SyliusCoreBundle extends AbstractResourceBundle
  37. {
  38.     public const VERSION '1.12.5';
  39.     public const VERSION_ID '11205';
  40.     public const MAJOR_VERSION '1';
  41.     public const MINOR_VERSION '12';
  42.     public const RELEASE_VERSION '5';
  43.     public const EXTRA_VERSION '';
  44.     public function getSupportedDrivers(): array
  45.     {
  46.         return [
  47.             SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
  48.         ];
  49.     }
  50.     public function boot(): void
  51.     {
  52.         parent::boot();
  53.         if ($this->container->getParameter('sylius_core.order_by_identifier')) {
  54.             $this->setDefaultOutputWalker(OrderByIdentifierSqlWalker::class);
  55.         }
  56.         $factory InflectorFactory::create();
  57.         $factory->withPluralRules(new Ruleset(
  58.             new Transformations(),
  59.             new Patterns(),
  60.             new Substitutions(new Substitution(new Word('taxon'), new Word('taxons'))),
  61.         ));
  62.         $inflector $factory->build();
  63.         Metadata::setInflector($inflector);
  64.     }
  65.     public function build(ContainerBuilder $container): void
  66.     {
  67.         parent::build($container);
  68.         $container->addCompilerPass(new CircularDependencyBreakingErrorListenerPass());
  69.         $container->addCompilerPass(new IgnoreAnnotationsPass());
  70.         $container->addCompilerPass(new LazyCacheWarmupPass());
  71.         $container->addCompilerPass(new LiipImageFiltersPass());
  72.         $container->addCompilerPass(new RegisterTaxCalculationStrategiesPass());
  73.         $container->addCompilerPass(new RegisterUriBasedSectionResolverPass());
  74.         $container->addCompilerPass(new ResolveShopUserTargetEntityPass());
  75.         $container->addCompilerPass(new Symfony5AuthenticationManagerPass());
  76.         $container->addCompilerPass(new Symfony6PrivateServicesPass());
  77.         $container->addCompilerPass(new TranslatableEntityLocalePass());
  78.         $container->addCompilerPass(new CancelOrderStateMachineCallbackPass());
  79.     }
  80.     /**
  81.      * @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
  82.      */
  83.     protected function getModelNamespace(): string
  84.     {
  85.         return 'Sylius\Component\Core\Model';
  86.     }
  87.     private function setDefaultOutputWalker(string $outputWalkerClass): void
  88.     {
  89.         $this->container
  90.             ->get('doctrine.orm.entity_manager')
  91.             ->getConfiguration()
  92.             ->setDefaultQueryHint(
  93.                 Query::HINT_CUSTOM_TREE_WALKERS,
  94.                 [$outputWalkerClass],
  95.             )
  96.         ;
  97.     }
  98. }