/** * Get data from request and create Pagination and PartialResponse events. * @param GetResponseEvent $event Event object with request */ public function onRequest(GetResponseEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } $request = $event->getRequest(); $pagination = new Pagination(); $partialResponse = new PartialResponse(); if ($request->query->has('page')) { $pagination->setPage($request->query->get('page')); } if ($request->query->has('sort')) { $pagination->setSort($request->query->get('sort')); } if ($request->query->has('items_per_page')) { $pagination->setItemsPerPage($request->query->get('items_per_page')); } if ($request->query->has('fields')) { $partialResponse->setFields($request->query->get('fields')); } $this->paginatorService->setPagination($pagination); $this->paginatorService->setPartialResponse($partialResponse); /** * Append all used parameters from get and post */ $this->paginatorService->setUsedRouteParams(array_merge($request->query->all(), $request->request->all())); }
function it_should_set_partial_response(PartialResponse $partialResponse) { $this->setPartialResponse($partialResponse)->shouldReturn($this); $this->getPartialResponse()->shouldReturn($partialResponse); $newPartialResponse = new PartialResponse(); $newPartialResponse->setFields('id,name,subject'); $this->setPartialResponse($newPartialResponse)->shouldReturn($this); $this->getPartialResponse()->shouldReturn($newPartialResponse); }