本文整理匯總了PHP中Slim\Http\Headers::extract方法的典型用法代碼示例。如果您正苦於以下問題:PHP Headers::extract方法的具體用法?PHP Headers::extract怎麽用?PHP Headers::extract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Slim\Http\Headers
的用法示例。
在下文中一共展示了Headers::extract方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
/**
* Constructor (private access)
*
* @param array|null $settings If present, these are used instead of global server variables
*/
private function __construct($settings = null)
{
if ($settings) {
$this->properties = $settings;
} else {
$env = array();
//The HTTP request method
$env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'];
//The IP
$env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
// Server params
$scriptName = $_SERVER['SCRIPT_NAME'];
// <-- "/foo/index.php"
$requestUri = $_SERVER['REQUEST_URI'];
// <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc"
$queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
// <-- "test=abc" or ""
// Physical path
if (strpos($requestUri, $scriptName) !== false) {
$physicalPath = $scriptName;
// <-- Without rewriting
} else {
$physicalPath = str_replace('\\', '', dirname($scriptName));
// <-- With rewriting
}
$env['SCRIPT_NAME'] = rtrim($physicalPath, '/');
// <-- Remove trailing slashes
$env['PATH_INFO'] = !empty($requestUri) && !empty($physicalPath) && strpos($requestUri, $physicalPath) === 0 ? substr_replace($requestUri, '', 0, strlen($physicalPath)) : $requestUri;
// <-- Remove physical path
$env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']);
// <-- Remove query string
$env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/');
// <-- Ensure leading slash
// Query string (without leading "?")
$env['QUERY_STRING'] = $queryString;
//Name of server host that is running the script
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
//Number of server port that is running the script
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
$headers = \Slim\Http\Headers::extract($_SERVER);
foreach ($headers as $key => $value) {
$env[$key] = $value;
}
//Is the application running under HTTPS or HTTP protocol?
$env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';
//Input stream (readable one time only; not available for multipart/form-data requests)
$rawInput = @file_get_contents('php://input');
if (!$rawInput) {
$rawInput = '';
}
$env['slim.input'] = $rawInput;
//Error stream
$env['slim.errors'] = @fopen('php://stderr', 'w');
// print_r($env); die;
$this->properties = $env;
}
}
示例2: __construct
/**
* Constructor
* @param \Slim\Environment $env
*/
public function __construct(\Slim\Environment $env)
{
$this->env = $env;
$this->headers = new \Slim\Http\Headers(\Slim\Http\Headers::extract($env));
$this->cookies = new \Slim\Helper\Set(\Slim\Http\Util::parseCookieHeader($env['HTTP_COOKIE']));
}
示例3: testExtractHeaders
public function testExtractHeaders()
{
$test = array('HTTP_HOST' => 'foo.com', 'SERVER_NAME' => 'foo', 'CONTENT_TYPE' => 'text/html', 'X_FORWARDED_FOR' => '127.0.0.1');
$results = \Slim\Http\Headers::extract($test);
$this->assertEquals(array('HTTP_HOST' => 'foo.com', 'CONTENT_TYPE' => 'text/html', 'X_FORWARDED_FOR' => '127.0.0.1'), $results);
}
示例4: __construct
/**
* Constructor (private access)
*
* @param array|null $settings If present, these are used instead of global server variables
*/
private function __construct($settings = null)
{
if ($settings) {
$this->properties = $settings;
} else {
$env = array();
//The HTTP request method
$env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'];
//The IP
$env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
// Root URI (physical path) and resource URI (virtual path)
$scriptName = str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME']);
// <-- "/physical/index.php"
$requestUri = $_SERVER['REQUEST_URI'];
// <-- "/physical/index.php/virtual?abc=123" or "/physical/virtual?abc=123"
$queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
// <-- "abc=123"
if (strpos($requestUri, $scriptName) === false) {
// With rewriting
$env['SCRIPT_NAME'] = str_replace('/' . basename($scriptName), '', $scriptName);
} else {
// Without rewriting
$env['SCRIPT_NAME'] = $scriptName;
}
$env['PATH_INFO'] = '/' . ltrim(str_replace(array($env['SCRIPT_NAME'], '?' . $queryString), '', $requestUri), '/');
// Query string (without leading "?")
$env['QUERY_STRING'] = $queryString;
//Name of server host that is running the script
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
//Number of server port that is running the script
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
$headers = \Slim\Http\Headers::extract($_SERVER);
foreach ($headers as $key => $value) {
$env[$key] = $value;
}
// $specialHeaders = array('CONTENT_TYPE', 'CONTENT_LENGTH', 'PHP_AUTH_USER', 'PHP_AUTH_PW', 'PHP_AUTH_DIGEST', 'AUTH_TYPE');
// foreach ($_SERVER as $key => $value) {
// $value = is_string($value) ? trim($value) : $value;
// if (strpos($key, 'HTTP_') === 0) {
// $env[substr($key, 5)] = $value;
// } elseif (strpos($key, 'X_') === 0 || in_array($key, $specialHeaders)) {
// $env[$key] = $value;
// }
// }
//Is the application running under HTTPS or HTTP protocol?
$env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';
//Input stream (readable one time only; not available for multipart/form-data requests)
$rawInput = @file_get_contents('php://input');
if (!$rawInput) {
$rawInput = '';
}
$env['slim.input'] = $rawInput;
//Error stream
$env['slim.errors'] = @fopen('php://stderr', 'w');
$this->properties = $env;
}
}
示例5: __construct
/**
* Constructor (private access)
*
* @param array|null $settings If present, these are used instead of global server variables
*/
private function __construct($settings = null)
{
if ($settings) {
$this->properties = $settings;
} else {
$env = array();
//The HTTP request method
$env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'];
//The IP
$env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
/**
* Application paths
*
* This derives two paths: SCRIPT_NAME and PATH_INFO. The SCRIPT_NAME
* is the real, physical path to the application, be it in the root
* directory or a subdirectory of the public document root. The PATH_INFO is the
* virtual path to the requested resource within the application context.
*
* With htaccess, the SCRIPT_NAME will be an absolute path (without file name);
* if not using htaccess, it will also include the file name. If it is "/",
* it is set to an empty string (since it cannot have a trailing slash).
*
* The PATH_INFO will be an absolute path with a leading slash; this will be
* used for application routing.
*/
if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) {
$env['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME'];
//Without URL rewrite
} else {
$env['SCRIPT_NAME'] = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
//With URL rewrite
}
$env['PATH_INFO'] = substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen($env['SCRIPT_NAME']));
if (strpos($env['PATH_INFO'], '?') !== false) {
$env['PATH_INFO'] = substr_replace($env['PATH_INFO'], '', strpos($env['PATH_INFO'], '?'));
//query string is not removed automatically
}
$env['SCRIPT_NAME'] = rtrim($env['SCRIPT_NAME'], '/');
$env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/');
//The portion of the request URI following the '?'
$env['QUERY_STRING'] = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
//Name of server host that is running the script
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
//Number of server port that is running the script
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
$headers = \Slim\Http\Headers::extract($_SERVER);
foreach ($headers as $key => $value) {
$env[$key] = $value;
}
// $specialHeaders = array('CONTENT_TYPE', 'CONTENT_LENGTH', 'PHP_AUTH_USER', 'PHP_AUTH_PW', 'PHP_AUTH_DIGEST', 'AUTH_TYPE');
// foreach ($_SERVER as $key => $value) {
// $value = is_string($value) ? trim($value) : $value;
// if (strpos($key, 'HTTP_') === 0) {
// $env[substr($key, 5)] = $value;
// } elseif (strpos($key, 'X_') === 0 || in_array($key, $specialHeaders)) {
// $env[$key] = $value;
// }
// }
//Is the application running under HTTPS or HTTP protocol?
$env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';
//Input stream (readable one time only; not available for multipart/form-data requests)
$rawInput = @file_get_contents('php://input');
if (!$rawInput) {
$rawInput = '';
}
$env['slim.input'] = $rawInput;
//Error stream
$env['slim.errors'] = @fopen('php://stderr', 'w');
$this->properties = $env;
}
}