本文整理汇总了PHP中Psr\Http\Message\RequestInterface::getQueryParams方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getQueryParams方法的具体用法?PHP RequestInterface::getQueryParams怎么用?PHP RequestInterface::getQueryParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getQueryParams方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* 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);
}
示例2: getPageFromRequest
/**
* @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;
}