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


PHP UserContext::toArray方法代码示例

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


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

示例1: postAction

 /**
  * @param Request $request
  * @param string  $id
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have right to edit the product
  *
  * @return JsonResponse
  */
 public function postAction(Request $request, $id)
 {
     $product = $this->findProductOr404($id);
     if ($this->objectFilter->filterObject($product, 'pim.internal_api.product.edit')) {
         throw new AccessDeniedHttpException();
     }
     $data = json_decode($request->getContent(), true);
     try {
         $data = $this->productEditDataFilter->filterCollection($data, null, ['product' => $product]);
     } catch (ObjectNotFoundException $e) {
         throw new BadRequestHttpException();
     }
     // TODO: PEF should never update groups, no way to do so from the screen, if a product is added to
     // another group during the save, this relation will be removed, other issue is that variant groups are never
     // passed here, so a product is always removed from it's variant group when saved
     unset($data['groups']);
     $data = $this->convertLocalizedAttributes($data);
     $this->updateProduct($product, $data);
     $violations = $this->validator->validate($product);
     $violations->addAll($this->localizedConverter->getViolations());
     if (0 === $violations->count()) {
         $this->productSaver->save($product);
         $normalizationContext = $this->userContext->toArray() + ['filter_type' => 'pim.internal_api.product_value.view', 'disable_grouping_separator' => true];
         return new JsonResponse($this->normalizer->normalize($product, 'internal_api', $normalizationContext));
     } else {
         $errors = ['values' => $this->normalizer->normalize($violations, 'internal_api', ['product' => $product])];
         return new JsonResponse($errors, 400);
     }
 }
开发者ID:SamirBoulil,项目名称:pim-community-dev,代码行数:38,代码来源:ProductController.php

示例2: postAction

 /**
  * @param Request $request
  * @param string  $code
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have permissions to edit the product
  *
  * @return JsonResponse
  */
 public function postAction(Request $request, $code)
 {
     $group = $this->groupRepository->findOneByIdentifier($code);
     if (null === $group) {
         throw new NotFoundHttpException(sprintf('Group with code "%s" not found', $code));
     }
     $data = json_decode($request->getContent(), true);
     $this->updater->update($group, $data);
     $violations = $this->validator->validate($group);
     if (0 < $violations->count()) {
         $errors = $this->violationNormalizer->normalize($violations, 'internal_api', $this->userContext->toArray());
         return new JsonResponse($errors, 400);
     }
     $this->saver->save($group);
     return new JsonResponse($this->normalizer->normalize($group, 'internal_api', $this->userContext->toArray()));
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:25,代码来源:GroupController.php

示例3: postAction

 /**
  * @param Request $request
  * @param string  $code
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have right to edit the product
  *
  * @return JsonResponse
  */
 public function postAction(Request $request, $code)
 {
     $variantGroup = $this->repository->findOneByIdentifier($code);
     if (null === $variantGroup) {
         throw new NotFoundHttpException(sprintf('Variant group with code "%s" not found', $code));
     }
     $data = json_decode($request->getContent(), true);
     $data = $this->convertLocalizedAttributes($data);
     $data = $this->variantGroupDataFilter->filterCollection($data, null);
     $this->updater->update($variantGroup, $data);
     $violations = $this->validator->validate($variantGroup);
     $violations->addAll($this->validator->validate($variantGroup->getProductTemplate()));
     $violations->addAll($this->attributeConverter->getViolations());
     if (0 < $violations->count()) {
         $errors = $this->violationNormalizer->normalize($violations, 'internal_api', $this->userContext->toArray() + ['product' => $variantGroup->getProductTemplate()]);
         return new JsonResponse($errors, 400);
     }
     $this->saver->save($variantGroup, ['copy_values_to_products' => true]);
     return new JsonResponse($this->normalizer->normalize($variantGroup, 'internal_api', $this->userContext->toArray() + ['with_variant_group_values' => true]));
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:29,代码来源:VariantGroupController.php

示例4: postAction

 /**
  * @param Request $request
  * @param string  $id
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have right to edit the product
  *
  * @return JsonResponse
  */
 public function postAction(Request $request, $id)
 {
     $product = $this->findProductOr404($id);
     if ($this->objectFilter->filterObject($product, 'pim.internal_api.product.edit')) {
         throw new AccessDeniedHttpException();
     }
     $data = json_decode($request->getContent(), true);
     try {
         $data = $this->productEditDataFilter->filterCollection($data, null, ['product' => $product]);
     } catch (ObjectNotFoundException $e) {
         throw new BadRequestHttpException();
     }
     $this->updateProduct($product, $data);
     $violations = $this->validator->validate($product);
     $violations->addAll($this->localizedConverter->getViolations());
     if (0 === $violations->count()) {
         $this->productSaver->save($product);
         $normalizationContext = $this->userContext->toArray() + ['filter_types' => ['pim.internal_api.product_value.view'], 'disable_grouping_separator' => true];
         return new JsonResponse($this->normalizer->normalize($product, 'internal_api', $normalizationContext));
     }
     $errors = ['values' => $this->normalizer->normalize($violations, 'internal_api', ['product' => $product])];
     return new JsonResponse($errors, 400);
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:32,代码来源:ProductController.php


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