/** * Adds config values to the public properties when a new object is created. * * @param array $config Configuration options: * - `'status'` _mixed_ : The response status (default: `[]`). * - `'cookies'` _array_ : set-cookie definition (default: `[]`). */ public function __construct($config = []) { $defaults = ['status' => 200, 'location' => null, 'format' => 'html', 'cookies' => [], 'classes' => ['cookies' => 'Lead\\Net\\Http\\Cookie\\SetCookies']]; $config = Set::merge($defaults, $config); parent::__construct($config); $this->status($config['status']); if ($config['location']) { $this->headers['Location'] = $config['location']; } $cookies = $this->_classes['cookies']; $this->headers->cookies = new $cookies(['data' => $config['cookies']]); }
/** * Adds config values to the public properties when a new object is created. * * @param array $config Configuration options: * - `'version'` _string_ : '1.1' * - `'method'` _string_ : 'GET' * - `'scheme'` _string_ : 'http' * - `'host'` _string_ : 'localhost' * - `'port'` _integer_: null * - `'username'` _string_ : null * - `'password'` _string_ : null * - `'path'` _string_ : null * - `'query'` _array_ : [] * - `'headers'` _array_ : [] * - `'type'` _string_ : null * - `'auth'` _mixed_ : null * - `'body'` _mixed_ : null */ public function __construct($config = []) { $defaults = ['scheme' => 'http', 'host' => 'localhost', 'port' => null, 'username' => null, 'password' => null, 'method' => 'GET', 'path' => '', 'query' => [], 'fragment' => '', 'auth' => null, 'cookies' => [], 'mode' => 'origin', 'classes' => ['cookies' => 'Lead\\Net\\Http\\Cookie\\Cookies']]; $config = Set::merge($defaults, $config); parent::__construct($config); if (!isset($this->headers['User-Agent'])) { $this->headers->prepend('User-Agent', 'Mozilla/5.0'); } if (!isset($this->headers['Connection'])) { $this->headers->prepend('Connection', 'Close'); } $this->mode($config['mode']); $this->scheme($config['scheme']); $this->port($config['port']); $this->host($config['host']); $this->username($config['username']); $this->password($config['password']); $this->method($config['method']); $this->path($config['path']); $this->query($config['query']); $this->fragment($config['fragment']); $this->auth($config['auth']); $cookies = $this->_classes['cookies']; $this->headers->cookies = new $cookies(['data' => $config['cookies']]); }