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


PHP Environment::has方法代码示例

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


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

示例1: createFromEnvironment

 /**
  * Create a normalized tree of UploadedFile instances from the Environment.
  *
  * @param Environment $env The environment
  *
  * @return array|null A normalized tree of UploadedFile instances or null if none are provided.
  */
 public static function createFromEnvironment(Environment $env)
 {
     if (is_array($env['slim.files']) && $env->has('slim.files')) {
         return $env['slim.files'];
     } elseif (isset($_FILES)) {
         return static::parseUploadedFiles($_FILES);
     }
     return [];
 }
开发者ID:tgfbikes,项目名称:php,代码行数:16,代码来源:UploadedFile.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::has方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。