本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getServerParams方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getServerParams方法的具体用法?PHP ServerRequestInterface::getServerParams怎么用?PHP ServerRequestInterface::getServerParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getServerParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toCake
/**
* Transform a PSR7 request into a CakePHP one.
*
* @param \Psr\Http\Message\ServerRequestInterface $request The PSR7 request.
* @return \Cake\Network\Request The transformed request.
*/
public static function toCake(PsrRequest $request)
{
$post = $request->getParsedBody();
$server = $request->getServerParams();
$files = static::getFiles($request);
if (!empty($files)) {
$post = Hash::merge($post, $files);
}
return new CakeRequest(['query' => $request->getQueryParams(), 'post' => $post, 'cookies' => $request->getCookieParams(), 'environment' => $server, 'params' => static::getParams($request), 'url' => $request->getUri()->getPath(), 'base' => $request->getAttribute('base', ''), 'webroot' => $request->getAttribute('webroot', '/')]);
}
示例2: server
/**
* Server data (e.g. $_SERVER)
* @return \PHPixie\HTTP\Data\Server
*/
public function server()
{
if ($this->server === null) {
$data = $this->serverRequest->getServerParams();
$this->server = $this->builder->serverData($data);
}
return $this->server;
}
示例3: 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;
}
示例4: 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;
}
示例5: __construct
/**
* Constructor
*
* @param Request $request
* @param Response $response
*/
public function __construct(RequestInterface $request, ResponseInterface $response)
{
$this->request = $request;
$this->response = $response;
$this->server = $this->request->getServerParams();
$request = $request->withAttribute('base_path', $this->getBasePath());
$request = $request->withAttribute('base_uri', $this->getBaseUri());
$request = $request->withAttribute('host_url', $this->getHostUrl());
//$x = $request->getAttribute('base_path', 'default');
}
示例6: _extractDataPSR7
private function _extractDataPSR7(ServerRequestInterface $request = null, $name = '')
{
$method = $request->getMethod();
$queryParams = $request->getQueryParams();
if ('GET' === $method) {
if ('' === $name) {
return $queryParams;
}
// Don't submit GET requests if the form's name does not exist
// in the request
if (!isset($queryParams[$name])) {
return;
}
return $queryParams[$name];
}
$serverParams = $request->getServerParams();
$uploadedFiles = $request->getUploadedFiles();
if ('' === $name) {
return $this->mergeParamsAndUploadedFiles($serverParams, $uploadedFiles);
}
if (isset($serverParams[$name]) || isset($uploadedFiles[$name])) {
$default = null;
$params = isset($serverParams[$name]) ? $serverParams[$name] : null;
$files = isset($uploadedFiles[$name]) ? $uploadedFiles[$name] : null;
return $this->mergeParamsAndUploadedFiles($params, $files);
}
// Don't submit the form if it is not present in the request
return;
}
示例7: checkRequestIsSecured
/**
* @param \Psr\Http\Message\ServerRequestInterface $request
*
* @throws \OAuth2\Exception\BadRequestExceptionInterface
*/
private function checkRequestIsSecured(ServerRequestInterface $request)
{
$server_params = $request->getServerParams();
if (empty($server_params['HTTPS']) || 'on' !== mb_strtolower($server_params['HTTPS'], '8bit')) {
throw $this->getExceptionManager()->getBadRequestException(ExceptionManagerInterface::ERROR_INVALID_REQUEST, 'The request must be secured.');
}
}
示例8: determineClientIpAddress
/**
* Find out the client's IP address from the headers available to us
*
* @param ServerRequestInterface $request PSR-7 Request
* @return string
*/
protected function determineClientIpAddress($request)
{
$ipAddress = null;
$serverParams = $request->getServerParams();
if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
$ipAddress = $serverParams['REMOTE_ADDR'];
}
$checkProxyHeaders = $this->checkProxyHeaders;
if ($checkProxyHeaders && !empty($this->trustedProxies)) {
if (!in_array($ipAddress, $this->trustedProxies)) {
$checkProxyHeaders = false;
}
}
if ($checkProxyHeaders) {
foreach ($this->headersToInspect as $header) {
if ($request->hasHeader($header)) {
$ip = trim(current(explode(',', $request->getHeaderLine($header))));
if ($this->isValidIpAddress($ip)) {
$ipAddress = $ip;
break;
}
}
}
}
return $ipAddress;
}
示例9: isValid
/**
* @param string $name
* @param array $options
*
* @return bool
*/
public function isValid($name, array $options = [])
{
$options += ['referer' => null, 'token' => null];
if (null === $options['token']) {
$params = $this->request->getParsedBody();
if (!isset($params[$name])) {
$this->invalidate();
return false;
} else {
$options['token'] = $params[$name];
}
}
$error = false;
$name .= $options['token'];
$config = array_get([self::TOKEN_KEY, $name], $this->storage, []);
$time = isset($config['expire']) ? $config['expire'] : 0;
if (time() > $time) {
$error = true;
}
if (!$error && null !== $options['referer']) {
$params = $this->request->getServerParams();
if (!isset($params['HTTP_REFERER']) || $params['HTTP_REFERER'] !== $options['referer']) {
$error = true;
}
}
$regenerate = array_key_exists('regenerate', $config) ? $config['regenerate'] : false;
if ($error || !$regenerate) {
array_remove([self::TOKEN_KEY, $name], $this->storage);
} elseif ($regenerate) {
$config['expire'] = time() + $config['time'];
array_set([self::TOKEN_KEY, $name], $config, $this->storage);
}
$this->invalidate();
return !$error;
}
示例10: __invoke
/**
* Handle authentication
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function __invoke(Request $request, Response $response, $next)
{
$path = $request->getUri()->getPath();
if ($path && $path != 'login') {
$serverParams = $request->getServerParams();
$authHeader = isset($serverParams['HTTP_X_AUTHORIZATION']) ? $serverParams['HTTP_X_AUTHORIZATION'] : null;
list($jwt) = sscanf($authHeader, 'Bearer %s');
if (!$jwt) {
return $response->withStatus(401)->write(json_encode(['message' => '401 Unauthorized']));
}
try {
$settings = $this->app->getContainer()->get('settings');
$secretKey = base64_decode($settings->get('jwt')['key']);
$token = JWT::decode($jwt, $secretKey, [$settings->get('jwt')['algorithm']]);
// Get the user info and add to the container
$this->app->getContainer()['currentUser'] = function ($c) use($token) {
return $token->data;
// user attributes
};
} catch (\Exception $e) {
return $response->withStatus(401)->write(json_encode(['message' => $e->getMessage()]));
}
}
$response = $next($request, $response);
return $response;
}
示例11: back
/**
* @param ServerRequestInterface $request
* @return BaseResponse|Response
*/
public static function back(ServerRequestInterface $request)
{
$serverParams = $request->getServerParams();
if (isset($serverParams['HTTP_REFERER'])) {
return static::redirect($serverParams['HTTP_REFERER']);
}
return static::factory(200, "<script>window.history.back()</script>");
}
示例12: 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;
}
示例13: getIPAddress
/**
* Returns the client IP address
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @return string|null IPv4 or IPv6 address or null if invalid
*/
protected function getIPAddress(\Psr\Http\Message\ServerRequestInterface $request)
{
$server = $request->getServerParams();
$flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;
if (isset($server['REMOTE_ADDR']) && ($ip = filter_var($server['REMOTE_ADDR'], FILTER_VALIDATE_IP, $flags)) !== false) {
return $ip;
}
}
示例14: 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);
}
示例15: __invoke
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
$server = $request->getServerParams();
$response = $next ? $next($request, $response) : $response;
$ms = (microtime(true) - $server['REQUEST_TIME_FLOAT']) * 1000;
$time = sprintf('%2.' . $this->config['digits'] . 'f%s', $ms, $this->config['suffix'] ? 'ms' : '');
return $response->withHeader($this->config['header'], $time);
}