* @license PHP License * @package WB * @subpackage rest */ /** * load base class */ WBClass::load('WBStream_Response'); /** * Stream Response HTTP * * Simple response class for HTTP stream * * @version 0.1.2 * @package WB * @subpackage rest */ class WBStream_Response_Http extends WBStream_Response { /** * Tell If Status Is OK * * @return bool */ public function isOK() { if (200 == $this->status) { return true; } return false; } /** * On Stream Set * * Extract HTTP-header and response status */ protected function onSetStream() { // check for result header foreach ($this->meta['wrapper_data'] as $line) { if (preg_match('/HTTP\\/1\\.\\d\\s+(\\d+)\\s+/', $line, $match)) { $this->status = $match[1]; break; } } foreach ($this->meta['wrapper_data'] as $line) { if (preg_match('/HTTP\\/1/', $line, $match)) { continue; } $line = array_map('trim', explode(':', $line, 2)); // invalid header if (2 > count($line)) { continue; } $this->header[strtolower($line[0])] = $line[1]; } $this->decodeContent(); } private function decodeContent() { $type = $this->getHeader('Content-Type'); if (empty($type)) { return; } $type = array_map('trim', explode(';', $type)); switch (strtolower($type[0])) { case 'application/json': $this->contentRaw = $this->content; $this->content = json_decode($this->content, true); break; default: break; } } }