protected function getFopenHandler() { if ($this->fopenHandler === null) { if (!file_exists($this->filePath)) { throw new Exception(Customweb_Core_String::_("File on path '@path' does not exists.")->format(array('@path' => $this->filePath))); } Customweb_Core_Util_Error::startErrorHandling(); $this->fopenHandler = fopen($this->filePath, 'r'); Customweb_Core_Util_Error::endErrorHandling(); $this->open = true; } return $this->fopenHandler; }
public function read($length = 0) { if ($length === 0) { $returnVal = $this->string; $this->position = strlen($this->string); } else { if ($length > 0) { Customweb_Core_Util_Error::startErrorHandling(); $returnVal = substr($this->string, $this->position, $length); Customweb_Core_Util_Error::endErrorHandling(); $this->position += $length; } else { // taken from file input stream implementation $returnVal = false; } } return $returnVal; }
/** * This method creates a stream socket to the server. * * @throws Customweb_Http_ConnectionException * @return stream resource */ protected function createSocketStream(Customweb_Core_Http_Request $request) { if ($request->isSecureConnection()) { if (!extension_loaded('openssl')) { throw new Customweb_Core_Http_Client_ConnectionException("You have to enable OpenSSL."); } } if ($this->isProxyActive()) { $host = $this->getProxyUrl()->getHost(); $port = $this->getProxyUrl()->getPort(); } else { // Change host if ssl is used: if ($request->isSecureConnection()) { $host = $this->getSslProtocol() . '://' . $request->getHost(); } else { $host = $request->getHost(); } $port = $request->getPort(); } $socket = $host . ':' . $port; Customweb_Core_Util_Error::startErrorHandling(); $fp = stream_socket_client($socket, $errno, $errstr, $this->getConnectionTimeout(), STREAM_CLIENT_CONNECT, $this->createStreamContext($request)); Customweb_Core_Util_Error::endErrorHandling(); if ($fp === false) { $errorMessage = 'Could not connect to the server. Host: ' . $socket . ' '; $errorMessage .= '(Error: ' . $errno . ', Error Message: ' . $errstr . ')'; throw new Customweb_Core_Http_Client_ConnectionException($errorMessage); } if (!(get_resource_type($fp) == 'stream')) { $errorMessage = 'Could not connect to the server. The returned socket was not a stream. Host: ' . $socket . ' '; throw new Customweb_Core_Http_Client_ConnectionException($errorMessage); } return $fp; }
public function skip($length) { Customweb_Core_Util_Error::startErrorHandling(); fgets($this->getSocket(), $length); Customweb_Core_Util_Error::endErrorHandling(); }
protected function getFileHandler() { if ($this->fileHandler === null) { $mode = 'w'; if ($this->isAppendingEnabled()) { $mode = 'a'; } try { Customweb_Core_Util_Error::startErrorHandling(); $this->fileHandler = fopen($this->filePath, $mode); Customweb_Core_Util_Error::endErrorHandling(); $this->open = true; } catch (Exception $e) { throw new Customweb_Core_Stream_IOException($e->getMessage()); } } return $this->fileHandler; }