_id = $id; $this->_context = stream_context_create(); return; } /** * Multiton. * * @param string $id ID. * @return \Hoa\Stream\Context * @throws \Hoa\Stream\Exception */ public static function getInstance($id) { if (empty($id)) { throw new Exception('Context ID must not be null.', 0); } if (false === static::contextExists($id)) { static::$_instances[$id] = new static($id); } return static::$_instances[$id]; } /** * Get context ID. * * @return string */ public function getId() { return $this->_id; } /** * Check if a context exists. * * @param string $id ID. * @return bool */ public static function contextExists($id) { return array_key_exists($id, static::$_instances); } /** * Set options. * Please, see http://php.net/context. * * @param array $options Options. * @return bool */ public function setOptions(array $options) { return stream_context_set_option($this->getContext(), $options); } /** * Set parameters. * Please, see http://php.net/context.params. * * @param array $parameters Parameters. * @return bool */ public function setParameters(array $parameters) { return stream_context_set_params($this->getContext(), $parameters); } /** * Get options. * * @return array */ public function getOptions() { return stream_context_get_options($this->getContext()); } /** * Get parameters. * . * @return array */ public function getParameters() { return stream_context_get_params($this->getContext()); } /** * Get context as a resource. * * @return resource */ public function getContext() { return $this->_context; } }