/** * Hydrates the domain object from the updating request. * * The domain object's attributes and relationships are hydrated * according to the JSON API specification. * * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request * @param \WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory * @param mixed $domainObject * @return mixed * @throws \Exception */ public function hydrateForUpdate(RequestInterface $request, ExceptionFactoryInterface $exceptionFactory, $domainObject) { $data = $request->getResource(); if ($data === null) { throw $exceptionFactory->createDataMemberMissingException($request); } $this->validateType($data, $exceptionFactory); $domainObject = $this->hydrateIdForUpdate($domainObject, $data, $exceptionFactory); $domainObject = $this->hydrateAttributes($domainObject, $data); $domainObject = $this->hydrateRelationships($domainObject, $data, $exceptionFactory); return $domainObject; }
/** * @param string $relationship * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request * @param \WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory * @param mixed $domainObject * @return mixed * @throws \WoohooLabs\Yin\JsonApi\Exception\RelationshipNotExists */ public function hydrateForRelationshipUpdate($relationship, RequestInterface $request, ExceptionFactoryInterface $exceptionFactory, $domainObject) { $relationshipHydrators = $this->getRelationshipHydrator($domainObject); if (isset($relationshipHydrators[$relationship]) === false) { throw $exceptionFactory->createRelationshipNotExists($relationship); } $relationshipHydrator = $relationshipHydrators[$relationship]; return $this->doHydrateRelationship($domainObject, $relationship, $relationshipHydrator, $exceptionFactory, $request->getParsedBody(), $request->getResource()); }