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


PHP Request::getServerParams方法代码示例

本文整理汇总了PHP中Slim\Http\Request::getServerParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getServerParams方法的具体用法?PHP Request::getServerParams怎么用?PHP Request::getServerParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Http\Request的用法示例。


在下文中一共展示了Request::getServerParams方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 /**
  * Execute the middleware.
  *
  * @param  \Slim\Http\Request  $req
  * @param  \Slim\Http\Response $res
  * @param  callable            $next
  * @return \Slim\Http\Response
  */
 public function __invoke(Request $req, Response $res, callable $next)
 {
     $uri = $req->getUri();
     $path = $this->filterTrailingSlash($uri);
     if ($uri->getPath() !== $path) {
         return $res->withStatus(301)->withHeader('Location', $path)->withBody($req->getBody());
     }
     //        if ($this->filterBaseurl($uri)) {
     //            return $res->withStatus(301)
     //                ->withHeader('Location', (string) $uri)
     //                ->withBody($req->getBody());
     //        }
     $server = $req->getServerParams();
     if (!isset($server['REQUEST_TIME_FLOAT'])) {
         $server['REQUEST_TIME_FLOAT'] = microtime(true);
     }
     $uri = $uri->withPath($path);
     $req = $this->filterRequestMethod($req->withUri($uri));
     $res = $next($req, $res);
     $res = $this->filterPrivateRoutes($uri, $res);
     // Only provide response calculation time in non-production env, tho.
     if ($this->settings['mode'] !== 'production') {
         $time = (microtime(true) - $server['REQUEST_TIME_FLOAT']) * 1000;
         $res = $res->withHeader('X-Response-Time', sprintf('%2.3fms', $time));
     }
     return $res;
 }
开发者ID:ninjanero,项目名称:slim-skeleton,代码行数:35,代码来源:CommonMiddleware.php

示例2: __invoke

 /**
  * Execute the middleware.
  *
  * @param Request  $request
  * @param Response $response
  * @param callable $next
  *
  * @return Response
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $server = $request->getServerParams();
     $requestTime = $server['REQUEST_TIME_FLOAT'] ?? microtime(true);
     // Call next middleware
     $response = $next($request, $response);
     $executionTime = microtime(true) - $requestTime;
     return $response->withHeader(self::HEADER, sprintf('%.3f', $executionTime));
 }
开发者ID:ansas,项目名称:php-component,代码行数:18,代码来源:Runtime.php

示例3: getOwnerId

 /**
  * @param \Slim\Http\Request $request
  * @return bool|int
  */
 private function getOwnerId(Request $request)
 {
     // Simply grab it from session, if available :P
     if ($this->session->has('user_id')) {
         return (int) $this->session->get('user_id');
     }
     // Or use HTTP Basic Auth.
     $serverParams = $request->getServerParams();
     $username = isset($serverParams['PHP_AUTH_USER']) ? $serverParams['PHP_AUTH_USER'] : '';
     $password = isset($serverParams['PHP_AUTH_PW']) ? $serverParams['PHP_AUTH_PW'] : '';
     if (isset($serverParams['HTTP_AUTHORIZATION'])) {
         if (preg_match("/Basic\\s+(.*)\$/i", $serverParams['HTTP_AUTHORIZATION'], $matches)) {
             list($username, $password) = explode(':', base64_decode($matches[1]));
         }
     }
     $users = $this->data(Models\Users::class);
     $user = $users->get([$users->primary(), 'password', 'username'], ['username' => $username])->fetch();
     $salt = $this->settings->get('salt_pwd');
     // TODO: We need better password hashing :sweat_smile:
     if ($user['password'] === md5($salt . $password)) {
         $userId = (int) $user[$users->primary()];
         $this->session->set('user_id', $userId);
         $this->session->set('username', $user['username']);
         return $userId;
     }
     return false;
 }
开发者ID:aswitahidayat,项目名称:phpindonesia.or.id-membership2,代码行数:31,代码来源:Middleware.php


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