/** * 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 []; }
/** * 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); }
public function testHas() { $this->property->setValue($this->bag, ['foo' => 'bar']); $this->assertTrue($this->bag->has('foo')); $this->assertFalse($this->bag->has('abc')); }
/** * 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)); }