vendor/sylius/resource-bundle/src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineODMDriver.php line 25

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\ResourceBundle\DependencyInjection\Driver\Doctrine;
  12. use Sylius\Bundle\ResourceBundle\Doctrine\ODM\MongoDB\TranslatableRepository;
  13. use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
  14. use Sylius\Component\Resource\Metadata\MetadataInterface;
  15. use Sylius\Component\Resource\Model\TranslatableInterface;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Definition;
  18. use Symfony\Component\DependencyInjection\Parameter;
  19. use Symfony\Component\DependencyInjection\Reference;
  20. @trigger_error(sprintf('The "%s" class is deprecated since Sylius 1.3. Doctrine MongoDB and PHPCR support will no longer be supported in Sylius 2.0.'DoctrineODMDriver::class), \E_USER_DEPRECATED);
  21. final class DoctrineODMDriver extends AbstractDoctrineDriver
  22. {
  23.     public function getType(): string
  24.     {
  25.         return SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM;
  26.     }
  27.     protected function addRepository(ContainerBuilder $containerMetadataInterface $metadata): void
  28.     {
  29.         $modelClass $metadata->getClass('model');
  30.         /** @var array $modelInterfaces */
  31.         $modelInterfaces class_implements($modelClass);
  32.         $repositoryClass in_array(TranslatableInterface::class, $modelInterfaces)
  33.             ? TranslatableRepository::class
  34.             : new Parameter('sylius.mongodb.odm.repository.class')
  35.         ;
  36.         if ($metadata->hasClass('repository')) {
  37.             $repositoryClass $metadata->getClass('repository');
  38.         }
  39.         $unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
  40.         $unitOfWorkDefinition
  41.             ->setFactory([new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'])
  42.             ->setPublic(false)
  43.         ;
  44.         $definition = new Definition($repositoryClass);
  45.         $definition->setArguments([
  46.             new Reference($metadata->getServiceId('manager')),
  47.             $unitOfWorkDefinition,
  48.             $this->getClassMetadataDefinition($metadata),
  49.         ]);
  50.         $container->setDefinition($metadata->getServiceId('repository'), $definition);
  51.     }
  52.     protected function getManagerServiceId(MetadataInterface $metadata): string
  53.     {
  54.         if ($objectManagerName $this->getObjectManagerName($metadata)) {
  55.             return sprintf('doctrine_mongodb.odm.%s_document_manager'$objectManagerName);
  56.         }
  57.         return 'doctrine_mongodb.odm.document_manager';
  58.     }
  59.     protected function getClassMetadataClassname(): string
  60.     {
  61.         return 'Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata';
  62.     }
  63. }