/**
  * Action logic
  *
  * @param RequestInterface $request Request
  * @param ResponseInterface $response Response
  * @return ResponseInterface
  * @throws HttpNotFoundException
  */
 public function run(RequestInterface $request, ResponseInterface $response)
 {
     /** @var \Psr\Http\Message\ServerRequestInterface $request */
     /** @var \Doctrine\ORM\EntityManager $entityManager */
     /** @var \App\Service\UrlParameters $urlParameters */
     /** @var \App\Module\Api\Domain\Entity\UserRepository $userRepository */
     $idUser = $request->getAttribute('id');
     $entityManager = $this->container->get('EntityManager');
     $userRepository = $entityManager->getRepository('Api:User');
     if ($idUser) {
         $result = $userRepository->searchUser($idUser);
         if (!$result) {
             throw new HttpNotFoundException('The user requested does not exist');
         }
     } else {
         $urlParams = $this->getContainer()->get('UrlParameters');
         $filters = $urlParams->filter('Api:User', $request->getQueryParams());
         $result = $userRepository->searchUsers($filters);
     }
     return new JsonResponse($result);
 }
Exemplo n.º 2
0
 /**
  * @param \Psr\Http\Message\RequestInterface $req
  * @return int
  */
 private function getPageFromRequest($req)
 {
     $page = isset($req->getQueryParams()['page']) ? $req->getQueryParams()['page'] : 1;
     $page = (int) $page;
     return $page < 1 ? 1 : $page;
 }