public function __construct(array $config = array())
{
$defaults = array('base' => null, 'url' => null, 'env' => array(), 'data' => array(), 'stream' => null, 'globals' => true, 'query' => array(), 'headers' => array());
$config += $defaults;
if ($config['globals']) {
if (isset($_SERVER)) {
$config['env'] += $_SERVER;
}
if (isset($_ENV)) {
$config['env'] += $_ENV;
}
if (isset($_GET)) {
$config['query'] += $_GET;
}
if (isset($_POST)) {
$config['data'] += $_POST;
}
}
$this->_env = $config['env'];
if (!isset($config['host'])) {
$config['host'] = $this->env('HTTP_HOST');
}
if (!isset($config['protocol'])) {
$config['protocol'] = $this->env('SERVER_PROTOCOL');
}
if ($config['protocol'] && strpos($config['protocol'], '/')) {
list($scheme, $version) = explode('/', $config['protocol']);
if (!isset($config['scheme'])) {
$config['scheme'] = strtolower($scheme) . ($this->env('HTTPS') ? 's' : '');
}
if (!isset($config['version'])) {
$config['version'] = $version;
}
}
$this->_base = $this->_base($config['base']);
$this->url = $this->_url($config['url']);
$config['headers'] += array('Content-Type' => $this->env('CONTENT_TYPE'), 'Content-Length' => $this->env('CONTENT_LENGTH'));
foreach ($this->_env as $name => $value) {
if ($name[0] === 'H' && strpos($name, 'HTTP_') === 0) {
$name = str_replace('_', ' ', substr($name, 5));
$name = str_replace(' ', '-', ucwords(strtolower($name)));
$config['headers'] += array($name => $value);
}
}
parent::__construct($config);
}