當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。