本文整理匯總了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;
}