Inheritance: extends Psr\Http\Message\ServerRequestInterface
示例#1
0
 /**
  * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
  * @throws \Exception
  */
 public function lintBody(RequestInterface $request)
 {
     $errorMessage = $this->lintMessage($request->getBody());
     if (empty($errorMessage) === false) {
         $this->exceptionFactory->createRequestBodyInvalidJsonException($request, $errorMessage, $this->includeOriginalMessage);
     }
 }
示例#2
0
 /**
  * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
  * @throws \Exception
  */
 public function lintBody(RequestInterface $request)
 {
     $errorMessage = $this->lintMessage($request->getBody()->__toString());
     if ($errorMessage) {
         throw $this->exceptionFactory->createRequestBodyInvalidJsonException($request, $errorMessage, $this->includeOriginalMessage);
     }
 }
 /**
  * @return \WoohooLabs\Yin\JsonApi\Document\AbstractErrorDocument
  */
 protected function createErrorDocument()
 {
     $errorDocument = new ErrorDocument();
     if ($this->includeOriginalBody === true) {
         $errorDocument->setMeta(["original" => json_decode($this->request->getBody(), true)]);
     }
     return $errorDocument;
 }
示例#4
0
 /**
  * Hydrates the domain object from the request based on the request method.
  *
  * If the request method is POST then the domain object is hydrated
  * as a create. If it is a PATCH request then the domain object is
  * hydrated as an update.
  *
  * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
  * @param \WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory
  * @param mixed $domainObject
  * @return mixed
  * @throws \WoohooLabs\Yin\JsonApi\Exception\ResourceTypeMissing
  */
 public function hydrate(RequestInterface $request, ExceptionFactoryInterface $exceptionFactory, $domainObject)
 {
     if ($request->getMethod() === "POST") {
         $domainObject = $this->hydrateForCreate($request, $exceptionFactory, $domainObject);
     } elseif ($request->getMethod() === "PATCH") {
         $domainObject = $this->hydrateForUpdate($request, $exceptionFactory, $domainObject);
     }
     return $domainObject;
 }
示例#5
0
 /**
  * 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 \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param callable $next
  * @return void|\Psr\Http\Message\ResponseInterface
  * @throws \Exception
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     $callable = $request->getAttribute($this->handlerAttribute);
     if ($callable === null) {
         return $this->getDispatchErrorResponse($response);
     }
     $jsonApi = new JsonApi($request, $response, $this->exceptionFactory, $this->serializer);
     if (is_array($callable) && is_string($callable[0])) {
         $object = $this->container !== null ? $this->container->get($callable[0]) : new $callable[0]();
         $response = $object->{$callable[1]}($jsonApi);
     } else {
         if (!is_callable($callable)) {
             $callable = $this->container->get($callable);
         }
         $response = call_user_func($callable, $jsonApi);
     }
     return $next($request, $response);
 }
示例#7
0
 /**
  * @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());
 }
示例#8
0
文件: JsonApi.php 项目: garethwi/yin
 /**
  * Disables sorting.
  *
  * If the current request contains sorting criteria, it throws a SortingNotSupported exception.
  *
  * @throws \WoohooLabs\Yin\JsonApi\Exception\SortingUnsupported
  */
 public function disableSorting()
 {
     if ($this->request->getQueryParam("sort") !== null) {
         throw $this->exceptionFactory->createSortingUnsupportedException($this->request);
     }
 }