Esempio n. 1
0
 /**
  * @param string                 $class
  * @param DocumentManager        $documentManager
  * @param ClassMetadata          $metadata
  * @param ResourceInterface|null $resource
  *
  * @return ObjectRepository
  */
 protected function createResourceRepository($class, DocumentManager $documentManager, ClassMetadata $metadata, ResourceInterface $resource = null)
 {
     if ($resource !== null && is_a($class, BaseRepositoryInterface::class, true)) {
         return new $class($documentManager, $documentManager->getUnitOfWork(), $metadata, $resource);
     }
     return parent::createRepository($documentManager, $metadata->getName());
 }
 /**
  * Initializes a new BasicDocumentPersister instance.
  *
  * @param Doctrine\ODM\MongoDB\DocumentManager $dm
  * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class
  */
 public function __construct(DocumentManager $dm, ClassMetadata $class)
 {
     $this->_dm = $dm;
     $this->_uow = $dm->getUnitOfWork();
     $this->_class = $class;
     $this->_documentName = $class->getName();
     $this->_collection = $dm->getDocumentCollection($class->name);
 }
 /**
  * @param ClassMetadata $metadata
  */
 private function setCustomRepositoryClass(ClassMetadata $metadata)
 {
     try {
         $resourceMetadata = $this->resourceRegistry->getByClass($metadata->getName());
     } catch (\InvalidArgumentException $exception) {
         return;
     }
     if ($resourceMetadata->hasClass('repository')) {
         $metadata->setCustomRepositoryClass($resourceMetadata->getClass('repository'));
     }
 }
Esempio n. 4
0
 /**
  * If the document is new, ignore shard key field value, otherwise throw an exception.
  * Also, shard key field should be present in actual document data.
  *
  * @param object $document
  * @param string $shardKeyField
  * @param array  $actualDocumentData
  *
  * @throws MongoDBException
  */
 private function guardMissingShardKey($document, $shardKeyField, $actualDocumentData)
 {
     $dcs = $this->uow->getDocumentChangeSet($document);
     $isUpdate = $this->uow->isScheduledForUpdate($document);
     $fieldMapping = $this->class->getFieldMappingByDbFieldName($shardKeyField);
     $fieldName = $fieldMapping['fieldName'];
     if ($isUpdate && isset($dcs[$fieldName]) && $dcs[$fieldName][0] != $dcs[$fieldName][1]) {
         throw MongoDBException::shardKeyFieldCannotBeChanged($shardKeyField, $this->class->getName());
     }
     if (!isset($actualDocumentData[$fieldName])) {
         throw MongoDBException::shardKeyFieldMissing($shardKeyField, $this->class->getName());
     }
 }
 function let(RegistryInterface $registry, LoadClassMetadataEventArgs $event, ClassMetadata $classMetadata)
 {
     $classMetadata->getName()->willReturn('Foo');
     $event->getClassMetadata()->willReturn($classMetadata);
     $this->beConstructedWith($registry);
 }
 /**
  * Initializes a new BasicDocumentPersister instance.
  *
  * @param Doctrine\ODM\MongoDB\DocumentManager $dm
  * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class
  */
 public function __construct(DocumentManager $dm, ClassMetadata $class)
 {
     $this->dm = $dm;
     $this->uow = $dm->getUnitOfWork();
     $this->class = $class;
     $this->documentName = $class->getName();
     $this->collection = $dm->getDocumentCollection($class->name);
     $this->cmd = $this->dm->getConfiguration()->getMongoCmd();
 }
 /**
  * {@inheritdoc}
  */
 public function getName()
 {
     return $this->classMetadata->getName();
 }
 public function generateTests(BundleInterface $bundle, ClassMetadata $class_metadata)
 {
     $document_name = explode('\\', $class_metadata->getName());
     $document_name = array_pop($document_name);
     // Controller Generator
     $dir = $bundle->getPath();
     $testControllerFile = $dir . '/Tests/Controller/' . $document_name . 'sControllerTest.php';
     if (file_exists($testControllerFile)) {
         throw new \RuntimeException(sprintf('Controller Test "%s" already exists', $document_name));
     }
     $parameters = array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle->getName(), 'controller' => $document_name . 'sControllerTest');
     $this->renderFile('test/TestController.php.twig', $testControllerFile, $parameters);
 }