Пример #1
0
 /**
  *	Builds and returns a SimpleXmlIterator.
  *
  *	@param string $xml XML document.
  *	@return SimpleXmlIterator Iterator.
  */
 protected static function _iterator($xml)
 {
     try {
         return new SimpleXmlIterator($xml);
     } catch (NativeException $Exception) {
         throw Exception::wrap($Exception);
     }
 }
Пример #2
0
 /**
  *	Parses an XML document and returns an array of data.
  *
  *	@param string $xml XML document.
  *	@return array Data.
  */
 public static function parse($xml)
 {
     $internal = libxml_use_internal_errors(true);
     $data = [];
     try {
         $iterator = new SimpleXmlIterator($xml);
     } catch (NativeException $Exception) {
         throw Exception::wrap($Exception);
     }
     foreach ($iterator as $key => $value) {
         $data[$key] = strval($value);
     }
     libxml_use_internal_errors($internal);
     return $data;
 }
Пример #3
0
 /**
  *	Wraps a native PHP exception.
  *
  *	@param NativeException Native exception.
  *	@return Exception Essence exception.
  */
 public static function wrap(NativeException $Exception)
 {
     return new Exception($Exception->getMessage(), $Exception->getCode(), $Exception);
 }
Пример #4
0
 /**
  *	Constructs the exception with the given HTTP status code, and the URL
  *	that triggered the error.
  *
  *	@param string $url URL.
  *	@param int $code HTTP status code.
  *	@param Exception $Previous Previous exception.
  */
 public function __construct($url, $code = 0, Exception $Previous = null)
 {
     $this->_url = $url;
     parent::__construct(isset($this->_messages[$code]) ? $this->_messages[$code] : 'HTTP error', $code, $Previous);
 }