/** * When a response is created, with pagination, it should copy the pagination to the new instance. * * @return [type] [description] */ public function testCreatesInstanceFromExistingResponseAlsoAddsPaginationToResponse() { $existing = new Response(); $pagination = new Pagination(30, 50, 0); $existing->setPagination($pagination); $response = Response::makeFromExisting($existing); $this->assertTrue($response->hasPagination()); $this->assertInstanceOf('\\Peakfijn\\GetSomeRest\\Http\\Pagination', $response->getPagination()); }
/** * Try and execute the requested route. * If the requested route is an API route, * catch all HttpExceptions and make it a nice response. * * @param Request $request * @return \Illuminate\Http\Response */ public function dispatch(Request $request) { // If the route is not an API route, // dont modify the response if (!$this->isApiRequest($request)) { return parent::dispatch($request); } try { $response = Response::makeFromExisting(parent::dispatch($request)); } catch (HttpExceptionInterface $exception) { $response = Response::makeFromException($exception); } catch (ModelNotFoundException $exception) { $response = Response::makeFromException(new NotFoundResourceException($exception->getModel())); } return $response->finalize($this->getMutator($request), $this->getEncoder($request), $request); }
/** * Create a response WITH pagination data from an existing response * * @param \Symfony\Component\HttpFoundation\Response $response * @param mixed $count * @param mixed $limit * @param mixed $offset * @return \Peakfijn\GetSomeRest\Http\Response */ public static function makeFromResponse(SymfonyResponse $response, $count = 0, $limit = 0, $offset = 0) { $response = Response::makeFromExisting($response); $response->setPagination(new static($count, $limit, $offset)); return $response; }