/** * {@inheritdoc} */ public function getDataSource(array $configuration, Parameters $parameters) { if (!array_key_exists('class', $configuration)) { throw new \InvalidArgumentException('"class" must be configured.'); } $repository = $this->documentManager->getRepository($configuration['class']); $queryBuilder = $repository->createQueryBuilder(self::QB_SOURCE_ALIAS); return new DataSource($queryBuilder); }
/** * Use a repository that implements RepositoryIdGenerator to generate the id. * * {@inheritDoc} */ public function generate($document, ClassMetadata $class, DocumentManagerInterface $dm, $parent = null) { if (null === $parent) { $parent = $class->parentMapping ? $class->getFieldValue($document, $class->parentMapping) : null; } $repository = $dm->getRepository($class->name); if (!$repository instanceof RepositoryIdInterface) { throw new IdException("ID could not be determined. Make sure the that the Repository '" . ClassUtils::getClass($repository) . "' implements RepositoryIdInterface"); } $id = $repository->generateId($document, $parent); if (!$id) { throw new IdException("ID could not be determined. Repository was unable to generate an ID"); } return $id; }
/** * {@inheritDoc} */ public function getRepository($className) { return $this->wrapped->getRepository($className); }
function it_creates_data_source_via_doctrine_phpcrodm_query_builder(DocumentManagerInterface $documentManager, DocumentRepository $documentRepository, QueryBuilder $queryBuilder, Parameters $parameters) { $documentManager->getRepository('App:Book')->willReturn($documentRepository); $documentRepository->createQueryBuilder('o')->willReturn($queryBuilder); $this->getDataSource(['class' => 'App:Book'], $parameters)->shouldHaveType(DataSource::class); }