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


PHP Environment::get方法代码示例

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


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

示例1: determineAuthorization

 /**
  * If HTTP_AUTHORIZATION does not exist tries to get it from
  * getallheaders() when available.
  *
  * @param Environment $environment The Slim application Environment
  *
  * @return Environment
  */
 public static function determineAuthorization(Environment $environment)
 {
     $authorization = $environment->get('HTTP_AUTHORIZATION');
     if (null === $authorization && is_callable('getallheaders')) {
         $headers = getallheaders();
         $headers = array_change_key_case($headers, CASE_LOWER);
         if (isset($headers['authorization'])) {
             $environment->set('HTTP_AUTHORIZATION', $headers['authorization']);
         }
     }
     return $environment;
 }
开发者ID:mateuszmackowiak,项目名称:swagger-codegen,代码行数:20,代码来源:Headers.php

示例2: createFromEnvironment

 /**
  * Create new Uri from environment.
  *
  * @param Environment $env
  *
  * @return self
  */
 public static function createFromEnvironment(Environment $env)
 {
     // Scheme
     $isSecure = $env->get('HTTPS');
     $scheme = empty($isSecure) || $isSecure === 'off' ? 'http' : 'https';
     // Authority: Username and password
     $username = $env->get('PHP_AUTH_USER', '');
     $password = $env->get('PHP_AUTH_PW', '');
     // Authority: Host
     if ($env->has('HTTP_HOST')) {
         $host = $env->get('HTTP_HOST');
     } else {
         $host = $env->get('SERVER_NAME');
     }
     // Authority: Port
     $port = (int) $env->get('SERVER_PORT', 80);
     if (preg_match('/^(\\[[a-fA-F0-9:.]+\\])(:\\d+)?\\z/', $host, $matches)) {
         $host = $matches[1];
         if ($matches[2]) {
             $port = (int) substr($matches[2], 1);
         }
     } else {
         $pos = strpos($host, ':');
         if ($pos !== false) {
             $port = (int) substr($host, $pos + 1);
             $host = strstr($host, ':', true);
         }
     }
     // Path
     $requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
     $requestScriptDir = dirname($requestScriptName);
     // parse_url() requires a full URL. As we don't extract the domain name or scheme,
     // we use a stand-in.
     $requestUri = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_PATH);
     $basePath = '';
     $virtualPath = $requestUri;
     if (stripos($requestUri, $requestScriptName) === 0) {
         $basePath = $requestScriptName;
     } elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {
         $basePath = $requestScriptDir;
     }
     if ($basePath) {
         $virtualPath = ltrim(substr($requestUri, strlen($basePath)), '/');
     }
     // Query string
     $queryString = $env->get('QUERY_STRING', '');
     // Fragment
     $fragment = '';
     // Build Uri
     $uri = new static($scheme, $host, $port, $virtualPath, $queryString, $fragment, $username, $password);
     if ($basePath) {
         $uri = $uri->withBasePath($basePath);
     }
     return $uri;
 }
开发者ID:Walk4Muscle,项目名称:garyslim3,代码行数:62,代码来源:Uri.php

示例3: createFromEnvironment

 /**
  * Create new Uri from environment.
  *
  * @param Environment $env
  *
  * @return self
  */
 public static function createFromEnvironment(Environment $env)
 {
     // Scheme
     if ($env->has('HTTP_X_FORWARDED_PROTO')) {
         $scheme = $env->get('HTTP_X_FORWARDED_PROTO');
         // Will be "http" or "https"
     } else {
         $isSecure = $env->get('HTTPS');
         $scheme = empty($isSecure) || $isSecure === 'off' ? 'http' : 'https';
     }
     // Authority: Username and password
     $username = $env->get('PHP_AUTH_USER', '');
     $password = $env->get('PHP_AUTH_PW', '');
     // Authority: Host
     if ($env->has('HTTP_X_FORWARDED_HOST')) {
         $host = trim(current(explode(',', $env->get('HTTP_X_FORWARDED_HOST'))));
     } elseif ($env->has('HTTP_HOST')) {
         $host = $env->get('HTTP_HOST');
     } else {
         $host = $env->get('SERVER_NAME');
     }
     // Authority: Port
     $pos = strpos($host, ':');
     if ($pos !== false) {
         $port = (int) substr($host, $pos + 1);
         $host = strstr($host, ':', true);
     } else {
         $port = (int) $env->get('SERVER_PORT', 80);
     }
     // Path
     $requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
     $requestScriptDir = dirname($requestScriptName);
     $requestUri = parse_url($env->get('REQUEST_URI'), PHP_URL_PATH);
     $basePath = '';
     $virtualPath = $requestUri;
     if (stripos($requestUri, $requestScriptName) === 0) {
         $basePath = $requestScriptName;
     } elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {
         $basePath = $requestScriptDir;
     }
     if ($basePath) {
         $virtualPath = ltrim(substr($requestUri, strlen($basePath)), '/');
     }
     // Query string
     $queryString = $env->get('QUERY_STRING', '');
     // Fragment
     $fragment = '';
     // Build Uri
     $uri = new static($scheme, $host, $port, $virtualPath, $queryString, $fragment, $username, $password);
     if ($basePath) {
         $uri = $uri->withBasePath($basePath);
     }
     return $uri;
 }
开发者ID:aodkrisda,项目名称:slim-3-framework-app,代码行数:61,代码来源:Uri.php


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