当前位置: 首页>>代码示例>>PHP>>正文


PHP ServerRequestInterface::getServerParams方法代码示例

本文整理汇总了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', '/')]);
 }
开发者ID:markstory,项目名称:cakephp-spekkoek,代码行数:16,代码来源:RequestTransformer.php

示例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;
 }
开发者ID:phpixie,项目名称:http,代码行数:12,代码来源:Request.php

示例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;
 }
开发者ID:weierophinney,项目名称:prophiler-psr7-middleware,代码行数:12,代码来源:Request.php

示例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;
 }
开发者ID:MidnightDesign,项目名称:zend-psr7bridge,代码行数:18,代码来源:Psr7ServerRequest.php

示例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');
 }
开发者ID:odan,项目名称:molengo,代码行数:16,代码来源:Http.php

示例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;
 }
开发者ID:pugx,项目名称:bindto,代码行数:29,代码来源:PSR7RequestTrait.php

示例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.');
     }
 }
开发者ID:spomky-labs,项目名称:oauth2-server-library,代码行数:12,代码来源:IssuerDiscoveryEndpoint.php

示例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;
 }
开发者ID:gboily,项目名称:rka-ip-address-middleware,代码行数:32,代码来源:IpAddress.php

示例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;
 }
开发者ID:cedtanghe,项目名称:elixir-security,代码行数:41,代码来源:CSRF.php

示例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;
 }
开发者ID:aodkrisda,项目名称:notes-api,代码行数:35,代码来源:Auth.php

示例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>");
 }
开发者ID:serendip811,项目名称:patio42,代码行数:12,代码来源:Response.php

示例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;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:11,代码来源:HttpFoundationFactory.php

示例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;
     }
 }
开发者ID:aimeos,项目名称:ai-slim,代码行数:14,代码来源:Slim.php

示例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);
 }
开发者ID:tonis-io,项目名称:oauth2,代码行数:14,代码来源:Util.php

示例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);
 }
开发者ID:tonis-io,项目名称:response-time,代码行数:14,代码来源:ResponseTime.php


注:本文中的Psr\Http\Message\ServerRequestInterface::getServerParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。