/** * Create a new item. * * @param Request $request * @param string|int $id * * @throws NotFoundHttpException * @throws RuntimeException * @throws UserProtectedException * @throws UserLimitReachedException * * @return mixed */ public function __invoke(Request $request, $id) { /** * @var $resourceType ResourceInterface */ list($resourceType, $format) = $this->extractAttributes($request); /* * Workaround to ensure stockLevels are not overwritten in a PUT request. * @see https://github.com/partkeepr/PartKeepr/issues/551 */ $data = json_decode($request->getContent(), true); if (array_key_exists('stockLevels', $data)) { unset($data['stockLevels']); } $requestData = json_encode($data); $data = $this->getItem($this->dataProvider, $resourceType, $id); $context = $resourceType->getDenormalizationContext(); $context['object_to_populate'] = $data; /** * @var $part Part */ $part = $this->serializer->deserialize($requestData, $resourceType->getEntityClass(), $format, $context); if (!$this->partService->isInternalPartNumberUnique($part->getInternalPartNumber(), $part)) { throw new InternalPartNumberNotUniqueException(); } return $part; }
/** * Injects the specific root node ID if "@local-tree-root" was specified * * @param Request $request * * @return mixed * * @throws RuntimeException * @throws PartLimitExceededException */ public function __invoke(Request $request) { /** * @var $resourceType ResourceInterface */ if ($this->partService->checkPartLimit()) { throw new PartLimitExceededException(); } list($resourceType, $format) = $this->extractAttributes($request); return $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext()); }
/** * Injects the specific root node ID if "@local-tree-root" was specified. * * @param Request $request * * @throws RuntimeException * @throws PartLimitExceededException * @throws InternalPartNumberNotUniqueException * * @return mixed */ public function __invoke(Request $request) { if ($this->partService->checkPartLimit()) { throw new PartLimitExceededException(); } /** * @var $resourceType ResourceInterface */ list($resourceType, $format) = $this->extractAttributes($request); /** * @var $part Part */ $part = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext()); if (!$this->partService->isInternalPartNumberUnique($part->getInternalPartNumber())) { throw new InternalPartNumberNotUniqueException(); } return $part; }