/** * Method which handles errors and convert them into exceptions. * * @throws Exception */ public static function handleErrors($errno, $errstr, $errfile, $errline) { $message = $errstr; $endOfFunctionName = strpos($errstr, '):'); if ($endOfFunctionName !== false) { $message = substr($errstr, $endOfFunctionName + 2); } self::$lastErrorMessage = trim($message); restore_error_handler(); throw new ErrorException(self::$lastErrorMessage, 0, $errno, $errfile, $errline); }
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 __wakeup() { Customweb_Core_Util_Error::deactivateErrorMessages(); date_default_timezone_set(@date_default_timezone_get()); Customweb_Core_Util_Error::activateErrorMessages(); // In case 'date' is set, we need to convert from PHP serialized object if (isset($this->date)) { if (isset($this->timezone_type) && isset($this->timezone) && $this->timezone_type == 3) { $this->dateTime = new DateTime($this->date, new DateTimeZone($this->timezone)); } else { $this->dateTime = new DateTime($this->date); } } else { $this->dateTime = new DateTime($this->dateTimeAsString); } }
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; }
public function skip($length) { Customweb_Core_Util_Error::startErrorHandling(); fgets($this->getSocket(), $length); Customweb_Core_Util_Error::endErrorHandling(); }
/** * Resolves the given file name over the include path. In case the file could not * be found the method throws an exception. * * @param string $fileName * @throws Customweb_Core_Exception_FileNotFoundException * @return string The absolute path to the file. */ public static function resolveFileOnIncludePath($fileName) { if (function_exists('stream_resolve_include_path')) { if (($path = stream_resolve_include_path($fileName)) === false) { throw new Customweb_Core_Exception_FileNotFoundException($fileName); } else { return $path; } } else { $include_path = explode(PATH_SEPARATOR, get_include_path()); Customweb_Core_Util_Error::deactivateErrorMessages(); foreach ($include_path as $path) { $file = realpath($path . '/' . $fileName); if (@file_exists($file)) { return $file; } } Customweb_Core_Util_Error::activateErrorMessages(); throw new Customweb_Core_Exception_FileNotFoundException($fileName); } }
/** * 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; }
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; }