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.     /**
  24.      * {@inheritdoc}
  25.      */
  26.     public function getType(): string
  27.     {
  28.         return SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     protected function addRepository(ContainerBuilder $containerMetadataInterface $metadata): void
  34.     {
  35.         $modelClass $metadata->getClass('model');
  36.         $repositoryClass in_array(TranslatableInterface::class, class_implements($modelClass))
  37.             ? TranslatableRepository::class
  38.             : new Parameter('sylius.mongodb.odm.repository.class')
  39.         ;
  40.         if ($metadata->hasClass('repository')) {
  41.             $repositoryClass $metadata->getClass('repository');
  42.         }
  43.         $unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
  44.         $unitOfWorkDefinition
  45.             ->setFactory([new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'])
  46.             ->setPublic(false)
  47.         ;
  48.         $definition = new Definition($repositoryClass);
  49.         $definition->setArguments([
  50.             new Reference($metadata->getServiceId('manager')),
  51.             $unitOfWorkDefinition,
  52.             $this->getClassMetadataDefinition($metadata),
  53.         ]);
  54.         $container->setDefinition($metadata->getServiceId('repository'), $definition);
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  58.      */
  59.     protected function getManagerServiceId(MetadataInterface $metadata): string
  60.     {
  61.         if ($objectManagerName $this->getObjectManagerName($metadata)) {
  62.             return sprintf('doctrine_mongodb.odm.%s_document_manager'$objectManagerName);
  63.         }
  64.         return 'doctrine_mongodb.odm.document_manager';
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      */
  69.     protected function getClassMetadataClassname(): string
  70.     {
  71.         return 'Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata';
  72.     }
  73. }