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

Open in your IDE?
  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\CircularDependencyBreakingErrorListenerPass;
  23. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\CircularDependencyBreakingExceptionListenerPass;
  24. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\IgnoreAnnotationsPass;
  25. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\LazyCacheWarmupPass;
  26. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\LiipImageFiltersPass;
  27. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterTaxCalculationStrategiesPass;
  28. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterUriBasedSectionResolverPass;
  29. use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\TranslatableEntityLocalePass;
  30. use Sylius\Bundle\CoreBundle\Doctrine\ORM\SqlWalker\OrderByIdentifierSqlWalker;
  31. use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
  32. use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
  33. use Sylius\Component\Resource\Metadata\Metadata;
  34. use Symfony\Component\DependencyInjection\ContainerBuilder;
  35. final class SyliusCoreBundle extends AbstractResourceBundle
  36. {
  37. public function getSupportedDrivers(): array
  38. {
  39. return [
  40. SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
  41. ];
  42. }
  43. public function boot(): void
  44. {
  45. parent::boot();
  46. if ($this->container->getParameter('sylius_core.order_by_identifier')) {
  47. $this->setDefaultOutputWalker(OrderByIdentifierSqlWalker::class);
  48. }
  49. $factory = InflectorFactory::create();
  50. $factory->withPluralRules(new Ruleset(
  51. new Transformations(),
  52. new Patterns(),
  53. new Substitutions(new Substitution(new Word('taxon'), new Word('taxons'))),
  54. ));
  55. $inflector = $factory->build();
  56. Metadata::setInflector($inflector);
  57. }
  58. public function build(ContainerBuilder $container): void
  59. {
  60. parent::build($container);
  61. $container->addCompilerPass(new CircularDependencyBreakingErrorListenerPass());
  62. $container->addCompilerPass(new CircularDependencyBreakingExceptionListenerPass());
  63. $container->addCompilerPass(new LazyCacheWarmupPass());
  64. $container->addCompilerPass(new RegisterTaxCalculationStrategiesPass());
  65. $container->addCompilerPass(new TranslatableEntityLocalePass());
  66. $container->addCompilerPass(new IgnoreAnnotationsPass());
  67. $container->addCompilerPass(new ResolveShopUserTargetEntityPass());
  68. $container->addCompilerPass(new RegisterUriBasedSectionResolverPass());
  69. $container->addCompilerPass(new LiipImageFiltersPass());
  70. $container->addCompilerPass(new CancelOrderStateMachineCallbackPass());
  71. }
  72. /**
  73. * @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
  74. */
  75. protected function getModelNamespace(): string
  76. {
  77. return 'Sylius\Component\Core\Model';
  78. }
  79. private function setDefaultOutputWalker(string $outputWalkerClass): void
  80. {
  81. $this->container
  82. ->get('doctrine.orm.entity_manager')
  83. ->getConfiguration()
  84. ->setDefaultQueryHint(
  85. Query::HINT_CUSTOM_TREE_WALKERS,
  86. [$outputWalkerClass],
  87. )
  88. ;
  89. }
  90. }