/**
  * @param PagingContext $context
  * @param PagingProperties $pagingConfiguration
  * @return array
  */
 private function reconstructQueryParams(PagingContext $context, PagingProperties $pagingConfiguration)
 {
     $originalQueryParams = $context->getQuery();
     $reconstructedParams = array();
     foreach ($pagingConfiguration->toArray() as $key => $value) {
         if (array_key_exists($key, $originalQueryParams)) {
             $reconstructedParams[$key] = sprintf('%s=%s', $key, $value);
         }
     }
     if (!array_key_exists('limit', $reconstructedParams)) {
         $reconstructedParams['limit'] = sprintf('limit=%s', $pagingConfiguration->getLimit());
     }
     return $reconstructedParams;
 }
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     $controller = $event->getController();
     if (is_array($controller)) {
         if (!$controller[0] instanceof RestServiceInterface) {
             return;
         }
         $reflection = new \ReflectionMethod($controller[0], $controller[1]);
     } elseif (is_object($controller) && !$controller instanceof \Closure) {
         if (!$controller instanceof RestServiceInterface) {
             return;
         }
         $reflection = new \ReflectionObject($controller);
         $reflection = $reflection->getMethod('__invoke');
     } else {
         return;
     }
     $request->attributes->set('_diamante_rest_service', true);
     if ($request->getMethod() == 'GET') {
         $pagingContext = PagingContext::fromRequest($request);
         $pagingContext->setHeaderContainer($this->container->get('diamante.api.headers.container'));
         $this->container->get('diamante.api.paging.provider')->setContext($pagingContext);
     }
     $methodParameters = new MethodParameters($reflection, $this->validator);
     if ($request->request->count()) {
         $request->attributes->set('properties', $request->request->all());
     }
     $methodParameters->addParameterBag($request->request);
     $methodParameters->addParameterBag($request->attributes);
     $methodParameters->addParameterBag($request->query);
     $methodParameters->putIn($request->attributes);
 }
 /**
  * @test
  */
 public function testPopulatePagingHeaders()
 {
     $pathToLinkMapping = [[$this->createPageLink(1), self::DUMMY_SERVER . $this->createPageLink(1)], [$this->createPageLink(6), self::DUMMY_SERVER . $this->createPageLink(6)], [$this->createPageLink(4), self::DUMMY_SERVER . $this->createPageLink(4)], [$this->createPageLink(2), self::DUMMY_SERVER . $this->createPageLink(2)]];
     $linksString = $this->getLinksString($pathToLinkMapping);
     $expectedHeaders = array('link' => array($linksString), 'x-total' => array(150));
     $headers = new HeaderBag();
     $this->pagingProvider->expects($this->exactly(2))->method('getContext')->will($this->returnValue($this->pagingContext));
     $this->pagingContext->expects($this->exactly(2))->method('getHeaderContainer')->will($this->returnValue($headers));
     $this->pagingInfo->expects($this->once())->method('getTotalRecords')->will($this->returnValue(150));
     $this->apiPagingServiceImpl->populatePagingHeaders($this->pagingInfo, $linksString);
     $this->assertEquals($expectedHeaders, $headers->all());
 }