public function testConstruct() { $expected = array('scheme' => 'http', 'host' => 'localhost', 'port' => '80', 'path' => null, 'username' => null, 'password' => null, 'body' => array()); $message = new Message($expected); $result = $message->to('array'); $this->assertEqual($expected, $result); }
/** * Adds config values to the public properties when a new object is created. * * @param array $config Configuration options : default value * - `scheme`: http * - `host`: localhost * - `port`: null * - `username`: null * - `password`: null * - `path`: null * - `version`: 1.1 * - `headers`: array * - `body`: null */ public function __construct(array $config = array()) { $defaults = array('scheme' => 'http', 'host' => 'localhost', 'port' => null, 'username' => null, 'password' => null, 'path' => null, 'protocol' => null, 'version' => '1.1', 'headers' => array(), 'body' => null); $config += $defaults; parent::__construct($config); if (strpos($this->host, '/') !== false) { list($this->host, $this->path) = explode('/', $this->host, 2); } $this->path = str_replace('//', '/', "/{$this->path}"); $this->protocol = $this->protocol ?: "HTTP/{$this->version}"; }
/** * Adds config values to the public properties when a new object is created. * * @param array $config Configuration options : default value * - `'protocol'` _string_: null * - `'version'` _string_: '1.1' * - `'scheme'` _string_: 'http' * - `'host'` _string_: 'localhost' * - `'port'` _integer_: null * - `'username'` _string_: null * - `'password'` _string_: null * - `'path'` _string_: null * - `'headers'` _array_: array() * - `'body'` _mixed_: null */ public function __construct(array $config = array()) { $defaults = array('protocol' => null, 'version' => '1.1', 'scheme' => 'http', 'host' => 'localhost', 'headers' => array()); $config += $defaults; foreach (array_intersect_key(array_filter($config), $defaults) as $key => $value) { $this->{$key} = $value; } parent::__construct($config); if (strpos($this->host, '/') !== false) { list($this->host, $this->path) = explode('/', $this->host, 2); } $this->path = str_replace('//', '/', "/{$this->path}"); $this->protocol = $this->protocol ?: "HTTP/{$this->version}"; }