コード例 #1
0
ファイル: UploadedFile.php プロジェクト: slimphp/Slim-Http
 /**
  * Create a normalized tree of UploadedFile instances from global server variables.
  *
  * @param array $globals The global server variables.
  *
  * @return array|null A normalized tree of UploadedFile instances or null if none are provided.
  */
 public static function createFromGlobals(array $globals)
 {
     $env = new Collection($globals);
     if (is_array($env['slim.files']) && $env->has('slim.files')) {
         return $env['slim.files'];
     } elseif (isset($_FILES)) {
         return static::parseUploadedFiles($_FILES);
     }
     return [];
 }
コード例 #2
0
ファイル: FactoryDefault.php プロジェクト: slimphp/Slim-Http
 /**
  * Make uri
  *
  * @param  array $globals The $_SERVER super-global
  * @return \Psr\Http\Message\UriInterface
  */
 public function makeUri(array $globals) : UriInterface
 {
     $env = new Collection($globals);
     // 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);
         }
     }
     // 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);
     // Query string
     $queryString = $env->get('QUERY_STRING', '');
     // Fragment
     $fragment = '';
     // Build Uri
     return new Uri($scheme, $host, $port, $requestUri, $queryString, $fragment, $username, $password);
 }
コード例 #3
0
 public function testHas()
 {
     $this->property->setValue($this->bag, ['foo' => 'bar']);
     $this->assertTrue($this->bag->has('foo'));
     $this->assertFalse($this->bag->has('abc'));
 }
コード例 #4
0
 /**
  * Does this collection have a given header?
  *
  * @param  string $key The case-insensitive header name
  *
  * @return bool
  */
 public function has($key)
 {
     return parent::has($this->normalizeKey($key));
 }