本文整理汇总了PHP中Symfony\Component\Serializer\Normalizer\NormalizerInterface类的典型用法代码示例。如果您正苦于以下问题:PHP NormalizerInterface类的具体用法?PHP NormalizerInterface怎么用?PHP NormalizerInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NormalizerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: normalize
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array())
{
$result = array('id' => $this->getId(), 'title' => $this->getTitle(), 'projectName' => $this->getProjectName(), 'status' => $this->getStatus(), 'running' => $this->isRunning(), 'properties' => $this->getProperties(), 'count' => array('pending' => $this->countStatus('pending'), 'running' => $this->countStatus('running'), 'succeeded' => $this->countStatus('succeeded'), 'failed' => $this->countStatus('failed')), 'progress' => $this->getProgress());
if (isset($context['run_details']) && $context['run_details']) {
$result['units'] = $normalizer->normalize($this->getUnits());
}
return $result;
}
示例2: indexAction
/**
* Get the list of all locales
*
* @return JsonResponse all activated locales
*/
public function indexAction()
{
$locales = $this->localeRepository->getActivatedLocales();
$filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view');
$normalizedLocales = $this->normalizer->normalize($filteredLocales, 'internal_api');
return new JsonResponse($normalizedLocales);
}
示例3: onKernelView
/**
* In an API context, converts any data to a JSON-LD response.
*
* @param GetResponseForControllerResultEvent $event
*
* @return JsonLdResponse|mixed
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$controllerResult = $event->getControllerResult();
if ($controllerResult instanceof Response) {
return;
}
$request = $event->getRequest();
$format = $request->attributes->get('_api_format');
if (self::FORMAT !== $format) {
return;
}
switch ($request->getMethod()) {
case Request::METHOD_POST:
$status = 201;
break;
case Request::METHOD_DELETE:
$status = 204;
break;
default:
$status = 200;
break;
}
$resourceType = $request->attributes->get('_resource_type');
$response = new JsonLdResponse($resourceType ? $this->normalizer->normalize($controllerResult, self::FORMAT, $resourceType->getNormalizationContext() + ['request_uri' => $request->getRequestUri()]) : $controllerResult, $status);
$event->setResponse($response);
}
示例4: process
/**
* {@inheritdoc}
*/
public function process($attribute)
{
$context = ['locales' => $this->localeManager->getActiveCodes()];
$flatAttribute = ['type' => $attribute->getAttributeType(), 'code' => $attribute->getCode()] + $this->transNormalizer->normalize($attribute, null, $context);
$flatAttribute = array_merge($flatAttribute, ['group' => $attribute->getGroup() ? $attribute->getGroup()->getCode() : null, 'unique' => (int) $attribute->isUnique(), 'useable_as_grid_filter' => (int) $attribute->isUseableAsGridFilter(), 'allowed_extensions' => implode(self::ITEM_SEPARATOR, $attribute->getAllowedExtensions()), 'metric_family' => $attribute->getMetricFamily(), 'default_metric_unit' => $attribute->getDefaultMetricUnit(), 'localizable' => (int) $attribute->isLocalizable(), 'scopable' => (int) $attribute->isScopable(), 'families' => $this->getAttributeFamilyCodes($attribute)]);
return $flatAttribute;
}
示例5: normalize
/**
* {@inheritdoc}
*/
public function normalize($attribute, $format = null, array $context = [])
{
$dateMin = null === $attribute->getDateMin() ? '' : $attribute->getDateMin()->format(\DateTime::ISO8601);
$dateMax = null === $attribute->getDateMax() ? '' : $attribute->getDateMax()->format(\DateTime::ISO8601);
$normalizedAttribute = $this->normalizer->normalize($attribute, 'json', $context) + ['id' => $attribute->getId(), 'wysiwyg_enabled' => $attribute->isWysiwygEnabled(), 'empty_value' => $this->emptyValueProvider->getEmptyValue($attribute), 'field_type' => $this->fieldProvider->getField($attribute), 'is_locale_specific' => (int) $attribute->isLocaleSpecific(), 'locale_specific_codes' => $attribute->getLocaleSpecificCodes(), 'max_characters' => $attribute->getMaxCharacters(), 'validation_rule' => $attribute->getValidationRule(), 'validation_regexp' => $attribute->getValidationRegexp(), 'number_min' => $attribute->getNumberMin(), 'number_max' => $attribute->getNumberMax(), 'decimals_allowed' => $attribute->isDecimalsAllowed(), 'negative_allowed' => $attribute->isNegativeAllowed(), 'date_min' => $dateMin, 'date_max' => $dateMax, 'metric_family' => $attribute->getMetricFamily(), 'default_metric_unit' => $attribute->getDefaultMetricUnit(), 'max_file_size' => $attribute->getMaxFileSize(), 'sort_order' => $attribute->getSortOrder()];
return $normalizedAttribute;
}
示例6: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
if (!$request->attributes->has('_resource_type') || self::FORMAT !== $request->attributes->get('_api_format')) {
return;
}
$exception = $event->getException();
$headers = [];
if ($exception instanceof HttpException) {
$status = $exception->getStatusCode();
$headers = $exception->getHeaders();
$data = $exception;
} elseif ($exception instanceof ValidationException) {
$status = Response::HTTP_BAD_REQUEST;
$data = $exception->getConstraintViolationList();
} elseif ($exception instanceof ExceptionInterface || $exception instanceof InvalidArgumentException) {
$status = Response::HTTP_BAD_REQUEST;
$data = $exception;
} else {
$status = Response::HTTP_INTERNAL_SERVER_ERROR;
$data = $exception;
}
$event->setResponse(new Response($this->normalizer->normalize($data, 'hydra-error'), $status, $headers));
}
示例7: onKernelException
/**
* Returns a list of violations normalized in the Hydra format.
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($exception instanceof ValidationException) {
$event->setResponse(new Response($this->normalizer->normalize($exception->getConstraintViolationList(), 'hydra-error'), Response::HTTP_BAD_REQUEST));
}
}
示例8: indexAction
/**
* Get the attribute collection
*
* @return JsonResponse
*/
public function indexAction()
{
$attributes = $this->attributeRepository->findAll();
$filteredAttributes = $this->collectionFilter->filterCollection($attributes, 'pim.internal_api.attribute.view');
$normalizedAttributes = $this->normalizer->normalize($filteredAttributes, 'internal_api');
return new JsonResponse($normalizedAttributes);
}
示例9: addAttributes
/**
* {@inheritdoc}
*/
public function addAttributes(ProductTemplateInterface $template, array $attributes, $locale)
{
$options = ['entity' => 'product', 'locale' => $locale, 'disable_grouping_separator' => true];
$values = $this->buildProductValuesFromTemplateValuesData($template, $attributes, $locale);
$valuesData = $this->normalizer->normalize($values, 'json', $options);
$template->setValuesData($valuesData);
}
示例10: process
/**
* {@inheritdoc}
*/
public function process($family)
{
$flatFamily = ['code' => $family->getCode()];
$familyLabels = $this->transNormalizer->normalize($family);
$flatFamily['label'] = $familyLabels['label'][$this->labelLocale];
return $flatFamily;
}
示例11: normalizeCompleteness
/**
* Normalize a completeness element
*
* @param array $completeness
* @param string $format
* @param array $context
*
* @return array
*/
protected function normalizeCompleteness($completeness, $format = null, array $context = array())
{
$missing = [];
foreach ($completeness['missing'] as $attribute) {
$missing[] = $attribute->getCode();
}
return ['missing' => $missing, 'completeness' => $this->normalizer->normalize($completeness['completeness'], $format, $context)];
}
示例12: __invoke
/**
* Converts a {@see \Symfony\Component\Debug\Exception\FlattenException}
* to a {@see \Dunglas\ApiBundle\JsonLd\Response}.
*
* @param FlattenException $exception
*
* @return Response
*/
public function __invoke(FlattenException $exception)
{
$exceptionClass = $exception->getClass();
if (is_a($exceptionClass, ExceptionInterface::class, true) || is_a($exceptionClass, InvalidArgumentException::class, true)) {
$exception->setStatusCode(Response::HTTP_BAD_REQUEST);
}
return new Response($this->normalizer->normalize($exception, 'hydra-error'), $exception->getStatusCode(), $exception->getHeaders());
}
示例13: getAction
/**
* Get a single family
*
* @param int $identifier
*
* @return JsonResponse
*/
public function getAction($identifier)
{
$family = $this->familyRepository->findOneByIdentifier($identifier);
if (null === $family) {
throw new NotFoundHttpException(sprintf('Family with code "%s" not found', $identifier));
}
return new JsonResponse($this->normalizer->normalize($family, 'json'));
}
示例14: normalize
/**
* {@inheritdoc}
*/
public function normalize($product, $format = null, array $context = [])
{
$normalizedProduct = $this->productNormalizer->normalize($product, 'json', $context);
$oldestLog = $this->versionManager->getOldestLogEntry($product);
$newestLog = $this->versionManager->getNewestLogEntry($product);
$normalizedProduct['meta'] = ['id' => $product->getId(), 'created' => $oldestLog !== null ? $this->versionNormalizer->normalize($oldestLog, 'internal_api') : null, 'updated' => $newestLog !== null ? $this->versionNormalizer->normalize($newestLog, 'internal_api') : null] + $this->getLabels($product) + $this->getAssociationMeta($product);
return $normalizedProduct;
}
示例15: listProductsAction
/**
* Display the products of a group
*
* @param string $identifier
*
* @return JsonResponse
*
* @AclAncestor("pim_enrich_product_index")
*/
public function listProductsAction($identifier)
{
$group = $this->groupRepository->findOneBy(['code' => $identifier]);
if (!$group) {
throw new NotFoundHttpException(sprintf('Group with code "%s" not found', $identifier));
}
return new JsonResponse($this->normalizer->normalize(['products' => $this->productRepository->getProductsByGroup($group, self::MAX_PRODUCTS), 'productCount' => $this->productRepository->getProductCountByGroup($group)], 'internal_api'));
}