本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getParam方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getParam方法的具体用法?PHP ServerRequestInterface::getParam怎么用?PHP ServerRequestInterface::getParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getParam方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPost
public function createPost(Request $request, Response $response)
{
$title = $request->getParam('title');
$content = $request->getParam('content');
$slug = trim($title);
$slug = str_replace(' ', '-', $slug);
$post = new Post();
$post->setTitle($title);
$post->setContent($content);
$post->setSlug($slug);
$this->em->persist($post);
$this->em->flush();
echo "Da them bai viet moi thanh cong";
}
示例2: __invoke
public function __invoke(Request $req, Response $res, $args = [])
{
$vaultName = $args['vaultName'];
if (!($vault = Vault::get($vaultName))) {
return $res->withStatus(404);
}
$operation = $req->getParam('operation');
$postData = file_get_contents('php://input');
$params = json_decode($postData, true);
try {
if ($operation === 'add') {
if (empty($params['Tags'])) {
return $res->withStatus(400);
}
$vault->addTags($params['Tags']);
return $res->withStatus(204);
} elseif ($operation === 'remove') {
if (empty($params['TagKeys'])) {
return $res->withStatus(204);
}
$vault->removeTags($params['TagKeys']);
return $res->withStatus(204);
}
return $res->withStatus(400);
} catch (\Gsandbox\Model\LimitExceededException $e) {
return $res->limitExceededException();
}
}
示例3: signinUser
public function signinUser(Request $request, Response $response)
{
$username = $request->getParam('username');
$password = $request->getParam('password');
$u = $this->em->getRepository('App\\Model\\User')->findOneBy(array('username' => $username));
if ($u == []) {
echo "Username nay khong ton tai";
} else {
if ($u->getPassword() != $password) {
echo "Ban nhap sai password";
} else {
echo "Ban da dang nhap thanh cong";
}
}
return $response;
}
示例4: __invoke
public function __invoke(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next)
{
$valid = $this->verify($requestInterface->getParam('g-recaptcha-response'), $requestInterface->getServerParams()['REMOTE_ADDR']);
if ($valid) {
return $next($requestInterface, $responseInterface);
} else {
throw new \Exception("Captcha Failed");
}
}
示例5: authenticate
public function authenticate(ServerRequestInterface $request, ResponseInterface $response)
{
if (empty($username = $request->getParam('username')) || empty($password = $request->getParam('password')) || empty($grant = $request->getParam('grant_type')) || $grant !== 'password') {
throw (new OAuth2Exception('Invalid parameters supplied for authentication'))->displayMessage(OAuth2Exception::BAD_CREDENTIALS)->response($response->withStatus(401));
}
$result = $this->authRepo->validateCredentials($username, $password);
if (empty($result)) {
throw (new OAuth2Exception('Wrong username or password'))->displayMessage(OAuth2Exception::BAD_CREDENTIALS)->response($response->withStatus(401));
}
$address = $this->getAddress();
$expiration = $this->getExpiration($this->config['expiration']);
$builder = (new Builder())->setIssuer($address)->setAudience($address)->setId(md5(uniqid(mt_rand(), true)), true)->setIssuedAt(time())->setNotBefore(time() + 60)->setExpiration($expiration)->setSubject($result['id']);
$customClaims = [];
foreach ($result as $claim => $value) {
if ($claim !== 'id') {
$customClaims[] = $claim;
$builder->set($claim, $value);
}
}
$token = $builder->set('cc', implode(',', $customClaims))->sign(new Sha256(), new Key($this->config['private-key']))->getToken();
// Retrieves the generated token
return $response->withHeader(\HTTP\Header\CacheControl::name(), \HTTP\Header\CacheControl::values([\HTTP\Header\CacheControl::NO_CACHE, \HTTP\Header\CacheControl::REVALIDATE]))->writeJson(['token' => sprintf('%s', $token), 'type' => 'Bearer', 'expires' => $expiration]);
}