/**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var MetadataContext $context */
     if ($context->hasResult()) {
         // metadata is already loaded
         return;
     }
     $entityClass = $context->getClassName();
     if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) {
         // only manageable entities are supported
         return;
     }
     // filter excluded fields on this stage though there is another processor doing the same
     // it is done due to performance reasons
     $allowedFields = $this->getAllowedFields($context->getConfig());
     $classMetadata = $this->doctrineHelper->getEntityMetadataForClass($entityClass);
     $entityMetadata = $this->entityMetadataFactory->createEntityMetadata($classMetadata);
     $fields = $classMetadata->getFieldNames();
     foreach ($fields as $fieldName) {
         if (!isset($allowedFields[$fieldName])) {
             continue;
         }
         $entityMetadata->addField($this->entityMetadataFactory->createFieldMetadata($classMetadata, $fieldName));
     }
     $associations = $classMetadata->getAssociationNames();
     foreach ($associations as $associationName) {
         if (!isset($allowedFields[$associationName])) {
             continue;
         }
         $entityMetadata->addAssociation($this->entityMetadataFactory->createAssociationMetadata($classMetadata, $associationName));
     }
     $context->setResult($entityMetadata);
 }
 /**
  * {@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 MetadataContext $context */
     if (!$context->hasResult()) {
         // metadata is not loaded
         return;
     }
     $config = $context->getConfig();
     if (empty($config)) {
         // a configuration does not exist
         return;
     }
     $this->loadMetadataForRelatedEntities($context->getResult(), $config, $context);
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var GetContext $context */
     if (!$context->hasResult()) {
         // no result
         return;
     }
     $data = $context->getResult();
     if (empty($data)) {
         // nothing to do because of empty result
         return;
     }
     $config = $context->getConfig();
     $context->setResult($this->objectNormalizer->normalizeObject($data, $config));
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var MetadataContext $context */
     if (!$context->hasResult()) {
         // metadata is not loaded
         return;
     }
     $config = $context->getConfig();
     if (empty($config)) {
         // a configuration does not exist
         return;
     }
     /** @var EntityMetadata $entityMetadata */
     $entityMetadata = $context->getResult();
     $this->normalizeMetadata($entityMetadata, $config);
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var GetListContext $context */
     if (!$context->hasResult()) {
         // no result
         return;
     }
     $data = $context->getResult();
     if (empty($data)) {
         // nothing to do because of empty result
         return;
     }
     $config = $context->getConfig();
     $normalizedData = [];
     foreach ($data as $key => $value) {
         $normalizedData[$key] = $this->objectNormalizer->normalizeObject($value, $config);
     }
     $context->setResult($normalizedData);
 }
 /**
  * {@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');
 }