Exemplo n.º 1
0
 /**
  * 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 [];
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * Retrieve a single derived request attribute.
  *
  * Retrieves a single derived request attribute as described in
  * getAttributes(). If the attribute has not been previously set, returns
  * the default value as provided.
  *
  * This method obviates the need for a hasAttribute() method, as it allows
  * specifying a default value to return if the attribute is not found.
  *
  * @see getAttributes()
  * @param string $name The attribute name.
  * @param mixed $default Default value to return if the attribute does not exist.
  * @return mixed
  */
 public function getAttribute($name, $default = null)
 {
     return $this->attributes->get($name, $default);
 }
 public function testCount()
 {
     $this->property->setValue($this->bag, ['foo' => 'bar', 'abc' => '123']);
     $this->assertEquals(2, $this->bag->count());
 }
Exemplo n.º 5
0
 /**
  * Remove header from collection
  *
  * @param  string $key The case-insensitive header name
  */
 public function remove($key)
 {
     parent::remove($this->normalizeKey($key));
 }