/**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var GetContext $context */
     if ($context->hasResult()) {
         // data already retrieved
         return;
     }
     $query = $context->getQuery();
     if (!$query instanceof QueryBuilder) {
         // unsupported query
         return;
     }
     $config = $context->getConfig();
     if (null === $config) {
         // an entity configuration does not exist
         return;
     }
     $result = $this->entitySerializer->serialize($query, $config);
     if (empty($result)) {
         $result = null;
     } elseif (count($result) === 1) {
         $result = reset($result);
     } else {
         throw new \RuntimeException('The result must have one or zero items.');
     }
     $context->setResult($result);
     // data returned by the EntitySerializer are already normalized
     $context->skipGroup('normalize_data');
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var GetListContext $context */
     if ($context->hasResult()) {
         // data already retrieved
         return;
     }
     $query = $context->getQuery();
     if (!$query instanceof QueryBuilder) {
         // unsupported query
         return;
     }
     $config = $context->getConfig();
     if (null === $config) {
         // an entity configuration does not exist
         return;
     }
     $context->setResult($this->entitySerializer->serialize($query, $config));
     // data returned by the EntitySerializer are already normalized
     $context->skipGroup('normalize_data');
 }
Beispiel #3
0
 /**
  * Serializes single entity
  *
  * @param mixed $id Entity id
  *
  * @return array|null
  */
 public function serializeOne($id)
 {
     $qb = $this->getItemQueryBuilder($id);
     $config = $this->getCachedSerializationConfig();
     $this->entitySerializer->prepareQuery($qb, $config);
     $entity = $qb->getQuery()->getResult();
     if (!$entity) {
         return null;
     }
     $this->checkFoundEntity($entity[0]);
     $serialized = $this->entitySerializer->serializeEntities((array) $entity, $this->class, $config);
     return $serialized[0];
 }
Beispiel #4
0
 /**
  * @param ManagerRegistry              $doctrine
  * @param ConfigManager                $configManager
  * @param BaseDataAccessorInterface    $dataAccessor
  * @param BaseDataTransformerInterface $dataTransformer
  * @param QueryHintResolverInterface   $queryHintResolver
  */
 public function __construct(ManagerRegistry $doctrine, ConfigManager $configManager, BaseDataAccessorInterface $dataAccessor, BaseDataTransformerInterface $dataTransformer, QueryHintResolverInterface $queryHintResolver)
 {
     parent::__construct($doctrine, new ExtendEntityFieldFilter($configManager), $dataAccessor, $dataTransformer, $queryHintResolver);
 }
Beispiel #5
0
 /**
  * @param ManagerRegistry              $doctrine
  * @param ConfigManager                $configManager
  * @param BaseDataAccessorInterface    $dataAccessor
  * @param BaseDataTransformerInterface $dataTransformer
  * @param QueryHintResolverInterface   $queryHintResolver
  */
 public function __construct(ManagerRegistry $doctrine, ConfigManager $configManager, BaseDataAccessorInterface $dataAccessor, BaseDataTransformerInterface $dataTransformer, QueryHintResolverInterface $queryHintResolver)
 {
     $doctrineHelper = new DoctrineHelper($doctrine);
     $fieldAccessor = new FieldAccessor($doctrineHelper, $dataAccessor, new ExtendEntityFieldFilter($configManager));
     parent::__construct($doctrineHelper, $dataAccessor, $dataTransformer, new QueryFactory($doctrineHelper, $queryHintResolver), $fieldAccessor, new ConfigNormalizer(), new DataNormalizer());
 }