/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var Context $context */ $entityClass = $context->getClassName(); if (false !== strpos($entityClass, '\\')) { // an entity class is already normalized return; } $context->setClassName($this->valueNormalizer->normalizeValue($entityClass, DataType::ENTITY_PLURAL_ALIAS, $context->getRequestType())); }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var Context $context */ if (!$context->hasConfigExtra(ExpandRelatedEntitiesConfigExtra::NAME)) { $filterValue = $context->getFilterValues()->get(self::FILTER_KEY); if (null !== $filterValue) { $includes = $this->valueNormalizer->normalizeValue($filterValue->getValue(), DataType::STRING, $context->getRequestType(), true); if (!empty($includes)) { $context->addConfigExtra(new ExpandRelatedEntitiesConfigExtra((array) $includes)); } } } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var Context $context */ if (!$context->hasConfigExtra(FilterFieldsConfigExtra::NAME)) { $fields = []; $filterValues = $context->getFilterValues()->getAll(self::FILTER_KEY); foreach ($filterValues as $filterValue) { $fields[$filterValue->getPath()] = (array) $this->valueNormalizer->normalizeValue($filterValue->getValue(), DataType::STRING, $context->getRequestType(), true); } if (!empty($fields)) { $context->addConfigExtra(new FilterFieldsConfigExtra($fields)); } } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var GetListContext $context */ if ($context->hasQuery()) { // a query is already built return; } $filterValues = $context->getFilterValues(); $filters = $context->getFilters(); foreach ($filters as $filterKey => $filter) { $filterValue = null; if ($filterValues->has($filterKey)) { $filterValue = $filterValues->get($filterKey); if ($filter instanceof StandaloneFilter) { $value = $this->valueNormalizer->normalizeValue($filterValue->getValue(), $filter->getDataType(), $context->getRequestType(), $filter->isArrayAllowed($filterValue->getOperator())); $filterValue->setValue($value); } } } }
/** * @param string $entityId * @param string[] $idFields * @param ClassMetadata $metadata * * @return array * * @throws \UnexpectedValueException if the given entity id cannot be normalized */ protected function reverseTransformCombinedEntityId($entityId, $idFields, ClassMetadata $metadata) { $fieldMap = array_flip($idFields); $normalized = []; foreach (explode(RestRequest::ARRAY_DELIMITER, $entityId) as $item) { $val = explode('=', $item); if (count($val) !== 2) { throw new \UnexpectedValueException(sprintf('Unexpected identifier value "%s" for composite primary key of the entity "%s".', $entityId, $metadata->getName())); } $key = $val[0]; $val = $val[1]; if (!isset($fieldMap[$key])) { throw new \UnexpectedValueException(sprintf('The entity identifier contains the key "%s" ' . 'which is not defined in composite primary key of the entity "%s".', $key, $metadata->getName())); } $dataType = $metadata->getTypeOfField($key); $normalized[$key] = $dataType !== DataType::STRING ? $this->valueNormalizer->normalizeValue($val, $dataType, [RequestType::REST]) : $val; unset($fieldMap[$key]); } if (!empty($fieldMap)) { throw new \UnexpectedValueException(sprintf('The entity identifier does not contain all keys ' . 'defined in composite primary key of the entity "%s".', $metadata->getName())); } return $normalized; }
/** * @dataProvider normalizeInvalidValueProvider */ public function testNormalizeInvalidValue($expectedExceptionMessage, $value, $dataType, $requestType) { $this->setExpectedException('\\UnexpectedValueException', $expectedExceptionMessage); $this->valueNormalizer->normalizeValue($value, $dataType, $requestType, true); }