* @copyright 2014 Fabian Grutschus. All rights reserved. * @license BSD * @link http://github.com/fabiang/xmpp */ namespace Fabiang\Xmpp\Exception; use Fabiang\Xmpp\Exception\InvalidArgumentException; /** * XML parser exception. * * @package Xmpp\Exception */ class XMLParserException extends RuntimeException { /** * Factory XML parsing exception. * * @param resource $parser * @throws static */ public static function create($parser) { if (!is_resource($parser) || 'xml' !== get_resource_type($parser)) { $message = 'Argument #1 of "' . __CLASS__ . '::' . __METHOD__ . '" must be a resource returned by "xml_parser_create"'; throw new InvalidArgumentException($message); } $code = xml_get_error_code($parser); $error = xml_error_string($code); $line = xml_get_current_line_number($parser); $column = xml_get_current_column_number($parser); return new static( sprintf('XML parsing error: "%s" at Line %d at column %d', $error, $line, $column), $code ); } }