예제 #1
0
 /**
  * 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 [];
 }
예제 #2
0
파일: Uri.php 프로젝트: neroreflex/gishiki
 /**
  * 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;
 }