当前位置: 首页>>代码示例>>PHP>>正文


PHP NormalizerInterface::normalize方法代码示例

本文整理汇总了PHP中Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP NormalizerInterface::normalize方法的具体用法?PHP NormalizerInterface::normalize怎么用?PHP NormalizerInterface::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Serializer\Normalizer\NormalizerInterface的用法示例。


在下文中一共展示了NormalizerInterface::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:10,代码来源:ProductTemplateBuilder.php

示例2: 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);
 }
开发者ID:PaskR,项目名称:DunglasApiBundle,代码行数:33,代码来源:ResponderViewListener.php

示例3: process

 /**
  * {@inheritdoc}
  */
 public function process($family)
 {
     $flatFamily = ['code' => $family->getCode()];
     $familyLabels = $this->transNormalizer->normalize($family);
     $flatFamily['label'] = $familyLabels['label'][$this->labelLocale];
     return $flatFamily;
 }
开发者ID:jurkowskij,项目名称:EnhancedConnectorBundle,代码行数:10,代码来源:FamilyToFlatArrayProcessor.php

示例4: 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);
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:12,代码来源:LocaleController.php

示例5: 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;
 }
开发者ID:techpub,项目名称:EnhancedConnectorBundle,代码行数:10,代码来源:AttributeToFlatArrayProcessor.php

示例6: 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));
     }
 }
开发者ID:PaskR,项目名称:DunglasApiBundle,代码行数:12,代码来源:ValidationExceptionListener.php

示例7: 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));
 }
开发者ID:rolebi,项目名称:DunglasApiBundle,代码行数:30,代码来源:RequestExceptionListener.php

示例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);
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:12,代码来源:AttributeController.php

示例9: 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;
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:10,代码来源:AttributeNormalizer.php

示例10: 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)];
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:17,代码来源:CompletenessCollectionNormalizer.php

示例11: __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());
 }
开发者ID:PaskR,项目名称:DunglasApiBundle,代码行数:16,代码来源:ExceptionAction.php

示例12: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($price, $format = null, array $context = [])
 {
     $price = $this->priceNormalizer->normalize($price, $format, $context);
     foreach ($price as $currency => $data) {
         $price[$currency] = $this->localizer->convertDefaultToLocalized($data, $context);
     }
     return $price;
 }
开发者ID:paulclarkin,项目名称:pim-community-dev,代码行数:11,代码来源:PriceNormalizer.php

示例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'));
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:15,代码来源:FamilyController.php

示例14: getAction

 /**
  * Get a single variant group
  *
  * @param int $identifier
  *
  * @return JsonResponse
  */
 public function getAction($identifier)
 {
     $variantGroup = $this->variantGroupRepo->findOneByCode($identifier);
     if (!$variantGroup) {
         throw new NotFoundHttpException(sprintf('Variant group with code "%s" not found', $identifier));
     }
     return new JsonResponse($this->normalizer->normalize($variantGroup, 'internal_api', ['with_variant_group_values' => true]));
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:15,代码来源:VariantGroupController.php

示例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'));
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:17,代码来源:GroupController.php


注:本文中的Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。