本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getCookieParams方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getCookieParams方法的具体用法?PHP ServerRequestInterface::getCookieParams怎么用?PHP ServerRequestInterface::getCookieParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getCookieParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toZend
/**
* Convert a PSR-7 ServerRequest to a Zend\Http server-side request.
*
* @param ServerRequestInterface $psr7Request
* @param bool $shallow Whether or not to convert without body/file
* parameters; defaults to false, meaning a fully populated request
* is returned.
* @return Zend\Request
*/
public static function toZend(ServerRequestInterface $psr7Request, $shallow = false)
{
if ($shallow) {
return new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), [], [], $psr7Request->getServerParams());
}
$zendRequest = new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), $psr7Request->getParsedBody() ?: [], self::convertUploadedFiles($psr7Request->getUploadedFiles()), $psr7Request->getServerParams());
$zendRequest->setContent($psr7Request->getBody());
return $zendRequest;
}
示例2: getData
/**
* {@inheritdoc}
*/
public function getData()
{
$headers = [];
foreach ($this->request->getHeaders() as $name => $values) {
$headers[$name] = implode(', ', $values);
}
$data = ['SERVER' => $this->request->getServerParams(), 'QUERY' => $this->request->getQueryParams(), 'COOKIES' => $this->request->getCookieParams(), 'HEADERS' => $headers, 'ATTRIBUTES' => $this->request->getAttributes()];
return $data;
}
示例3: read
/**
* {@inheritdoc}
*/
public function read($sessionId)
{
$cookies = $this->request->getCookieParams();
if (!is_null($decoded = json_decode($cookies, true)) && is_array($decoded)) {
if (isset($decoded[$sessionId])) {
$data = $decoded[$sessionId];
if (isset($data['expires']) && Chronos::now()->getTimestamp() <= $data['expires']) {
return $data['data'];
}
}
}
return '';
}
示例4: __invoke
public function __invoke(Request $request)
{
/** Check for token on header */
if (isset($this->options['header'])) {
if ($request->hasHeader($this->options['header'])) {
$header = $request->getHeader($this->options['header'])[0];
if (preg_match($this->options['regex'], $header, $matches)) {
return $matches[1];
}
}
}
/** If nothing on header, try query parameters */
if (isset($this->options['parameter'])) {
if (!empty($request->getQueryParams()[$this->options['parameter']])) {
return $request->getQueryParams()[$this->options['parameter']];
}
}
/** If nothing on parameters, try cookies */
if (isset($this->options['cookie'])) {
$cookie_params = $request->getCookieParams();
if (!empty($cookie_params[$this->options["cookie"]])) {
return $cookie_params[$this->options["cookie"]];
}
}
/** If nothing until now, check argument as last try */
if (isset($this->options['argument'])) {
if ($route = $request->getAttribute('route')) {
$argument = $route->getArgument($this->options['argument']);
if (!empty($argument)) {
return $argument;
}
}
}
throw new TokenNotFoundException('Token not found');
}
示例5: __invoke
/**
* {@inheritdoc}
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, \Closure $next)
{
if (isset($request->getCookieParams()[self::COOKIE])) {
$token = $request->getCookieParams()[self::COOKIE];
} else {
//Making new token
$token = substr(base64_encode(openssl_random_pseudo_bytes(self::TOKEN_LENGTH)), 0, self::TOKEN_LENGTH);
//We can alter response cookies
$response = $response->withAddedHeader('Set-Cookie', Cookie::create(self::COOKIE, $token, self::LIFETIME, $request->getAttribute('basePath'), $request->getAttribute('cookieDomain'))->packHeader());
}
if ($this->isRequired($request) && !$this->compare($token, $this->fetchToken($request))) {
//Invalid CSRF token
return $response->withStatus(412, 'Bad CSRF Token');
}
return $next($request->withAttribute(static::ATTRIBUTE, $token), $response);
}
示例6: __invoke
/**
* {@inheritdoc}
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, \Closure $next)
{
$cookies = $request->getCookieParams();
$outerID = null;
if (isset($cookies[self::COOKIE])) {
if ($this->store()->isStarted()) {
$outerID = $this->store()->getID();
}
//Mounting ID retrieved from cookies
$this->store()->setID($cookies[self::COOKIE]);
}
$response = $next();
if (empty($this->store) && $this->container->hasInstance(SessionStore::class)) {
//Store were started by itself
$this->store = $this->container->get(SessionStore::class);
}
if (!empty($this->store) && ($this->store->isStarted() || $this->store->isDestroyed())) {
$response = $this->setCookie($request, $response, $this->store, $cookies);
}
//Restoring original session, not super efficient operation
if (!empty($outerID)) {
$this->store->setID($outerID);
}
return $response;
}
示例7: handleRequest
/**
* Handles a frontend request based on the _GP "eID" variable.
*
* @param ServerRequestInterface $request
* @return NULL|\Psr\Http\Message\ResponseInterface
*/
public function handleRequest(ServerRequestInterface $request)
{
// Timetracking started
$configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
if (empty($configuredCookieName)) {
$configuredCookieName = 'be_typo_user';
}
if ($request->getCookieParams()[$configuredCookieName]) {
$GLOBALS['TT'] = new TimeTracker();
} else {
$GLOBALS['TT'] = new NullTimeTracker();
}
$GLOBALS['TT']->start();
// Hook to preprocess the current request
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
$hookParameters = array();
GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
}
unset($hookFunction);
unset($hookParameters);
}
// Remove any output produced until now
$this->bootstrap->endOutputBufferingAndCleanPreviousOutput();
return $this->dispatch($request);
}
示例8: checkSiteAccess
/**
* Checks if the user has access to the site. This is the case if the site
* is public or if the user has entered the access key.
* @param ServerRequestInterface $serverRequest The request.
* @return boolean True if the user has access, false otherwise.
*/
private function checkSiteAccess(ServerRequestInterface $serverRequest)
{
$correctKey = $this->website->getConfig()->get(Config::OPTION_ACCESS_CODE);
if (empty($correctKey)) {
// The website doesn't use an access key
return true;
}
// Check for key in cookie
$cookies = $serverRequest->getCookieParams();
if (isset($cookies["key"]) && $cookies["key"] === $correctKey) {
return true;
}
// Newly entered key
$postData = $serverRequest->getParsedBody();
if (isset($postData["key"])) {
$text = $this->website->getText();
if ($postData["key"] === $correctKey) {
$text->addMessage($text->t("access_key.access_granted"));
return true;
} else {
$text->addMessage($text->t("access_key.entered_wrong_key"));
return false;
}
}
return false;
}
示例9: __invoke
/**
* Execute the middleware.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
if (session_status() === PHP_SESSION_DISABLED) {
throw new RuntimeException('PHP sessions are disabled');
}
if (session_status() === PHP_SESSION_ACTIVE) {
throw new RuntimeException('Failed to start the session: already started by PHP.');
}
//Session name
$name = $this->name ?: session_name();
session_name($name);
//Session id
$id = $this->id;
if (empty($id)) {
$cookies = $request->getCookieParams();
if (!empty($cookies[$name])) {
$id = $cookies[$name];
}
}
if (!empty($id)) {
session_id($id);
}
session_start();
$request = self::startStorage($request, isset($_SESSION[self::STORAGE_KEY]) ? $_SESSION[self::STORAGE_KEY] : []);
$response = $next($request, $response);
if (session_status() === PHP_SESSION_ACTIVE && session_name() === $name) {
$_SESSION[self::STORAGE_KEY] = self::stopStorage($request);
session_write_close();
}
return $response;
}
示例10: initializeTimeTracker
/**
* Timetracking started depending if a Backend User is logged in
*
* @return void
*/
protected function initializeTimeTracker()
{
$configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user';
/** @var TimeTracker timeTracker */
$this->timeTracker = GeneralUtility::makeInstance(TimeTracker::class, $this->request->getCookieParams()[$configuredCookieName] ? true : false);
$this->timeTracker->start();
}
示例11: logIn
/**
* @param Request $request
* @return Request
*/
protected function logIn(Request $request)
{
$header = $request->getHeaderLine('authorization');
$parts = explode(';', $header);
$actor = new Guest();
if (isset($parts[0]) && starts_with($parts[0], $this->prefix)) {
$token = substr($parts[0], strlen($this->prefix));
if (($accessToken = AccessToken::find($token)) && $accessToken->isValid()) {
$actor = $accessToken->user;
$actor->updateLastSeen()->save();
} elseif (isset($parts[1]) && ($apiKey = ApiKey::valid($token))) {
$userParts = explode('=', trim($parts[1]));
if (isset($userParts[0]) && $userParts[0] === 'userId') {
$actor = User::find($userParts[1]);
}
}
}
if ($actor->exists) {
$locale = $actor->getPreference('locale');
} else {
$locale = array_get($request->getCookieParams(), 'locale');
}
if ($locale && $this->locales->hasLocale($locale)) {
$this->locales->setLocale($locale);
}
return $request->withAttribute('actor', $actor ?: new Guest());
}
示例12: getToken
/**
* Get the access token referred to by the request cookie.
*
* @param Request $request
* @return AccessToken|null
*/
protected function getToken(Request $request)
{
$token = array_get($request->getCookieParams(), 'flarum_remember');
if ($token) {
return AccessToken::find($token);
}
}
示例13: __invoke
/**
* {@inheritdoc}
*/
public function __invoke(Request $request, Response $response, callable $out = null)
{
if (($token = array_get($request->getCookieParams(), 'flarum_remember')) && ($accessToken = AccessToken::valid($token))) {
$this->app->instance('flarum.actor', $user = $accessToken->user);
$user->updateLastSeen()->save();
}
return $out ? $out($request, $response) : $response;
}
示例14: createRequest
/**
* {@inheritdoc}
*/
public function createRequest(ServerRequestInterface $psrRequest)
{
$parsedBody = $psrRequest->getParsedBody();
$parsedBody = is_array($parsedBody) ? $parsedBody : array();
$request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString());
$request->headers->replace($psrRequest->getHeaders());
return $request;
}
示例15: convertRequestFromPsr7
/**
* Converts a PSR-7 request into an OAuth2 request.
*
* @param ServerRequestInterface $psrRequest
* @return Request
*/
public static function convertRequestFromPsr7(ServerRequestInterface $psrRequest)
{
$headers = [];
foreach ($psrRequest->getHeaders() as $header => $value) {
$headers[$header] = implode(';', $value);
}
return new Request($psrRequest->getQueryParams(), is_array($psrRequest->getParsedBody()) ? $psrRequest->getParsedBody() : [], $psrRequest->getAttributes(), $psrRequest->getCookieParams(), self::getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString(), $headers);
}