本文整理汇总了PHP中Slim\Http\Environment::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::get方法的具体用法?PHP Environment::get怎么用?PHP Environment::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Environment
的用法示例。
在下文中一共展示了Environment::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: determineAuthorization
/**
* If HTTP_AUTHORIZATION does not exist tries to get it from
* getallheaders() when available.
*
* @param Environment $environment The Slim application Environment
*
* @return Environment
*/
public static function determineAuthorization(Environment $environment)
{
$authorization = $environment->get('HTTP_AUTHORIZATION');
if (null === $authorization && is_callable('getallheaders')) {
$headers = getallheaders();
$headers = array_change_key_case($headers, CASE_LOWER);
if (isset($headers['authorization'])) {
$environment->set('HTTP_AUTHORIZATION', $headers['authorization']);
}
}
return $environment;
}
示例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;
}
示例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;
}