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