/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (empty($definition) || empty($definition[ConfigUtil::FIELDS]) || !is_array($definition[ConfigUtil::FIELDS])) { // a configuration of fields does not exist or a description is not needed return; } $entityClass = $context->getClassName(); if (!$this->entityConfigProvider->hasConfig($entityClass)) { // only configurable entities are supported return; } $fields = array_keys($definition[ConfigUtil::FIELDS]); foreach ($fields as $fieldName) { $fieldConfig = $definition[ConfigUtil::FIELDS][$fieldName]; $config = $this->findFieldConfig($entityClass, $fieldName, $fieldConfig); if (null !== $config) { if (null === $fieldConfig) { $fieldConfig = []; } if (!isset($fieldConfig[ConfigUtil::LABEL])) { $fieldConfig[ConfigUtil::LABEL] = new Label($config->get('label')); } $definition[ConfigUtil::FIELDS][$fieldName] = $fieldConfig; } } $context->setResult($definition); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ /** @var array|null $definition */ $definition = $context->getResult(); if (empty($definition) || ConfigUtil::isExcludeAll($definition)) { // nothing to do return $definition; } $entityClass = $context->getClassName(); if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) { return $definition; } $expandRelations = $context->get(ExpandRelatedEntitiesConfigExtra::NAME); $associations = $this->doctrineHelper->getEntityMetadataForClass($entityClass)->getAssociationMappings(); foreach ($associations as $fieldName => $mapping) { if (!$this->isAssociationCompletionRequired($fieldName, $definition)) { continue; } if (!in_array($fieldName, $expandRelations)) { continue; } $extras = array_filter($context->getExtras(), function ($item) { if ($item instanceof ExpandRelatedEntitiesConfigExtra || $item instanceof FilterFieldsConfigExtra) { return false; } return true; }); $config = $this->configProvider->getConfig($mapping['targetEntity'], $context->getVersion(), $context->getRequestType(), $extras); $definition[ConfigUtil::FIELDS][$fieldName] = $config; } $context->setResult([ConfigUtil::EXCLUSION_POLICY => ConfigUtil::EXCLUSION_POLICY_NONE, ConfigUtil::FIELDS => $definition[ConfigUtil::FIELDS]]); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ /** @var array $definition */ $definition = $context->getResult(); if (empty($definition) || !array_key_exists(ConfigUtil::FIELDS, $definition)) { // virtual fields is added only if a definition of fields exists return; } $entityClass = $context->getClassName(); $virtualFields = $this->virtualFieldProvider->getVirtualFields($entityClass); if (!empty($virtualFields)) { foreach ($virtualFields as $field) { $query = $this->virtualFieldProvider->getVirtualFieldQuery($entityClass, $field); $propertyPath = $this->getPropertyPath($query); if (!empty($propertyPath)) { $definition[ConfigUtil::FIELDS][$field][ConfigUtil::PROPERTY_PATH] = $propertyPath; if (!empty($query['select']['label']) && $context->hasExtra(DescriptionsConfigExtra::NAME)) { $definition[ConfigUtil::FIELDS][$field][ConfigUtil::LABEL] = new Label($query['select']['label']); } } } $context->setResult($definition); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (empty($definition)) { // an entity configuration does not exist return; } $entityClass = $context->getClassName(); if (!isset($definition[ConfigUtil::LABEL])) { $entityName = $this->entityClassNameProvider->getEntityClassName($entityClass); if ($entityName) { $definition[ConfigUtil::LABEL] = $entityName; } } if (!isset($definition[ConfigUtil::PLURAL_LABEL])) { $entityPluralName = $this->entityClassNameProvider->getEntityClassPluralName($entityClass); if ($entityPluralName) { $definition[ConfigUtil::PLURAL_LABEL] = $entityPluralName; } } if (!isset($definition[ConfigUtil::DESCRIPTION]) && $this->entityConfigProvider->hasConfig($entityClass)) { $definition[ConfigUtil::DESCRIPTION] = new Label($this->entityConfigProvider->getConfig($entityClass)->get('description')); } $context->setResult($definition); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var GetListContext $context */ $documentBuilder = $this->documentBuilderFactory->createDocumentBuilder(); try { if ($context->hasErrors()) { $documentBuilder->setErrorCollection($context->getErrors()); // remove errors from the Context to avoid processing them by other processors $context->resetErrors(); } elseif ($context->hasResult()) { $result = $context->getResult(); if (empty($result)) { $documentBuilder->setDataCollection($result); } else { $documentBuilder->setDataCollection($result, $context->getMetadata()); } } $context->setResult($documentBuilder->getDocument()); } catch (\Exception $e) { $context->setResponseStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR); $error = new Error(); $error->setInnerException($e); $documentBuilder = $this->documentBuilderFactory->createDocumentBuilder(); $documentBuilder->setErrorObject($error); $context->setResult($documentBuilder->getDocument()); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { $result = $context->getResult(); if (array_key_exists(JsonApiDocument::DATA, $result) && !is_array($result[JsonApiDocument::DATA])) { throw new \RuntimeException(sprintf('The "%s" section must be an array.', JsonApiDocument::DATA)); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var CollectPublicResourcesContext $context */ $context->setResult($context->getResult()->filter(function (PublicResource $resource) { return !$this->entityExclusionProvider->isIgnoredEntity($resource->getEntityClass()); })); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { if (!$context->hasResult()) { throw new NotFoundHttpException('Unsupported request.'); } elseif (null === $context->getResult()) { throw new NotFoundHttpException('An entity with the requested identifier does not exist.'); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { $config = $context->getResult(); if (null !== $config) { // a config already exists return; } $context->setResult(null); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var CollectPublicResourcesContext $context */ $resources = $context->getResult(); $entities = $this->dictionaryProvider->getSupportedEntityClasses(); foreach ($entities as $entityClass) { $resources->add(new PublicResource($entityClass)); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { if (!$context->hasResult()) { // no result return; } $data = $context->getResult(); if ($data instanceof Proxy && !$data->__isInitialized()) { $data->__load(); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (empty($definition)) { // nothing to normalize return; } $this->normalizeDefinition($definition); $context->setResult($definition); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (empty($definition)) { // nothing to update return; } $this->setCustomizationHandler($definition, $context); $context->setResult($definition); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var CollectPublicResourcesContext $context */ $resources = $context->getResult(); $configs = $this->configManager->getConfigs('extend', null, true); foreach ($configs as $config) { if ($config->is('is_extend') && $config->is('owner', ExtendScope::OWNER_CUSTOM)) { $resources->add(new PublicResource($config->getId()->getClassName())); } } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (empty($definition)) { // an entity configuration does not exist return; } $this->normalizeAttribute($definition, ConfigUtil::LABEL); $this->normalizeAttribute($definition, ConfigUtil::PLURAL_LABEL); $this->normalizeAttribute($definition, ConfigUtil::DESCRIPTION); $context->setResult($definition); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var RelationConfigContext $context */ $config = $context->getResult(); if (null !== $config) { // a config already exists return; } $config = $this->loadConfig($context->getClassName(), $context->getVersion()); if (null !== $config) { $this->addConfigToContext($context, $config); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { if (!$context->hasResult()) { // no result return; } $data = $context->getResult(); foreach ($data as $value) { if ($value instanceof Proxy && !$value->__isInitialized()) { $value->__load(); } } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var GetListContext $context */ if (!$context->hasResult()) { $query = $context->getQuery(); if (null === $query) { throw new NotFoundHttpException('Unsupported request.'); } else { throw new NotFoundHttpException(sprintf('Unsupported query type: %s.', is_object($query) ? get_class($query) : gettype($query))); } } elseif (!is_array($context->getResult())) { throw new NotFoundHttpException('Getting a list of entities failed.'); } }
/** * {@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); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $filters = $context->getFilters(); if (null === $filters) { // a filters' configuration does not exist return; } $definition = $context->getResult(); if (null === $definition) { // an entity configuration does not exist return; } $this->collect($filters, ConfigUtil::FILTERS, $definition); $context->setFilters($filters); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { $result = $context->getResult(); if (!is_array($result)) { throw new \RuntimeException('The result must be an array.'); } $rootSections = [JsonApiDocument::DATA, JsonApiDocument::ERRORS, JsonApiDocument::META]; if (count(array_intersect(array_keys($result), $rootSections)) === 0) { throw new \RuntimeException(sprintf('The result must contain at least one of the following sections: %s.', implode(', ', $rootSections))); } if (array_key_exists(JsonApiDocument::DATA, $result) && array_key_exists(JsonApiDocument::ERRORS, $result)) { throw new \RuntimeException(sprintf('The sections "%s" and "%s" must not coexist in the result.', JsonApiDocument::DATA, JsonApiDocument::ERRORS)); } if (array_key_exists(JsonApiDocument::INCLUDED, $result) && !array_key_exists(JsonApiDocument::DATA, $result)) { throw new \RuntimeException(sprintf('The result can contain the "%s" section only together with the "%s" section.', JsonApiDocument::INCLUDED, JsonApiDocument::DATA)); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (!isset($definition[ConfigUtil::FIELDS]) || !is_array($definition[ConfigUtil::FIELDS]) || !ConfigUtil::isExcludeAll($definition)) { // expected normalized configs return; } $entityClass = $context->getClassName(); if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) { // only manageable entities are supported return; } if ($this->updateRelations($definition, $entityClass)) { $context->setResult($definition); } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (null === $definition || !isset($definition[ConfigUtil::FIELDS]) || !is_array($definition[ConfigUtil::FIELDS])) { // a configuration of fields does not exist or a fix is not needed return; } $entityClass = $context->getClassName(); $reservedFieldNames = array_intersect(array_keys($definition[ConfigUtil::FIELDS]), ['id', 'type']); foreach ($reservedFieldNames as $fieldName) { if ('type' === $fieldName || 'id' === $fieldName && !$this->isIdentifierField($entityClass, $fieldName)) { $this->renameReservedField($definition[ConfigUtil::FIELDS], $entityClass, $fieldName); } } $context->setResult($definition); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $filters = $context->getFilters(); if (empty($filters)) { // nothing to normalize return; } $fields = ConfigUtil::getArrayValue($filters, ConfigUtil::FIELDS); if (ConfigUtil::isExcludeAll($filters)) { $fields = ConfigUtil::removeExclusions($fields); } else { $entityClass = $context->getClassName(); if ($this->doctrineHelper->isManageableEntityClass($entityClass)) { $fields = ConfigUtil::removeExclusions($this->completeFilters($fields, $entityClass, $context->getResult())); } } $context->setFilters([ConfigUtil::EXCLUSION_POLICY => ConfigUtil::EXCLUSION_POLICY_ALL, ConfigUtil::FIELDS => $fields]); }
/** * {@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 ConfigContext $context */ /** @var array|null $definition */ $definition = $context->getResult(); if (empty($definition) || ConfigUtil::isExcludeAll($definition)) { // nothing to normalize return; } if (ConfigUtil::getArrayValue($definition, ConfigUtil::DEFINITION)) { $definition = ConfigUtil::getArrayValue($definition, ConfigUtil::DEFINITION); } $fields = ConfigUtil::getArrayValue($definition, ConfigUtil::FIELDS); $entityClass = $context->getClassName(); if ($this->doctrineHelper->isManageableEntityClass($entityClass)) { $fields = $this->completeDefinition($fields, $entityClass, $context->getVersion(), $context->getRequestType(), $context->getExtras()); } $context->setResult([ConfigUtil::EXCLUSION_POLICY => ConfigUtil::EXCLUSION_POLICY_ALL, ConfigUtil::FIELDS => $fields]); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ /** @var array|null $definition */ $definition = $context->getResult(); if (empty($definition) || !is_array($definition[ConfigUtil::FIELDS])) { // nothing to do return; } $fieldsDefinition = $definition[ConfigUtil::FIELDS]; $entityClass = $context->getClassName(); if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) { return; } $filterFieldsConfig = $context->get(FilterFieldsConfigExtra::NAME); $this->filterFields($entityClass, $fieldsDefinition, $filterFieldsConfig); $this->filterAssociations($entityClass, $fieldsDefinition, $filterFieldsConfig); $context->setResult([ConfigUtil::EXCLUSION_POLICY => ConfigUtil::EXCLUSION_POLICY_ALL, ConfigUtil::FIELDS => $fieldsDefinition]); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $definition = $context->getResult(); if (empty($definition) || empty($definition[ConfigUtil::FIELDS]) || !is_array($definition[ConfigUtil::FIELDS])) { // a configuration of fields does not exist or a normalization is not needed return; } $fields = array_keys($definition[ConfigUtil::FIELDS]); foreach ($fields as $fieldName) { $fieldConfig = $definition[ConfigUtil::FIELDS][$fieldName]; if (null !== $fieldConfig && is_array($fieldConfig)) { $this->normalizeAttribute($fieldConfig, ConfigUtil::LABEL); $this->normalizeAttribute($fieldConfig, ConfigUtil::DESCRIPTION); $definition[ConfigUtil::FIELDS][$fieldName] = $fieldConfig; } } $context->setResult($definition); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var ConfigContext $context */ $maxRelatedEntities = $context->getMaxRelatedEntities(); if (null === $maxRelatedEntities || $maxRelatedEntities < 0) { // there is no limit to the number of related entities return; } $definition = $context->getResult(); if (empty($definition)) { // nothing to update return; } $entityClass = $context->getClassName(); if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) { // only manageable entities are supported return; } $this->setLimits($definition, $entityClass, $maxRelatedEntities); $context->setResult($definition); }