* @license PHP License * @package WB * @subpackage rest */ /** * load base class */ // WBClass::load(); /** * Stream Response * * Simple response class * * @version 0.1.2 * @package WB * @subpackage rest */ class WBStream_Response extends WBStdClass { protected $status = 0; protected $header = array(); protected $meta = array(); protected $content = ''; protected $contentRaw = null; /** * Construtor * * @param array configation parameters */ public function __construct($parameter = array()) { } /** * Get Status Code * * @return int */ final public function getStatus() { return $this->status; } /** * Tell If Status Is OK * * @return bool */ public function isOK() { if (0 > $this->status) { return false; } return true; } final public function setStream($stream) { $this->status = 0; $this->contentRaw = null; $this->content = stream_get_contents($stream); if (false === $this->content) { $this->status = -1; } $this->meta = stream_get_meta_data($stream); $this->header = array(); $this->onSetStream(); } /** * On Stream Set * * Things to do when stream was set */ protected function onSetStream() { } /** * Get Header Data * * @param string header line mame * @param string default value, if header is not set * @return string|array */ final public function getHeader($key = null, $default = '') { if (is_null($key)) { return $this->header; } $key = strtolower($key); if (isset($this->header[$key])) { return $this->header[$key]; } return $default; } /** * Get Response Data * * @return string */ public function getContent() { return $this->content; } /** * Get RAW Response Data * * @return string */ public function getRawContent() { if (empty($this->contentRaw)) { return $this->content; } return $this->contentRaw; } }