From 9a743ca0f69d11a5bee037aeb2573100d9c073ff Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 9 Nov 2021 16:14:34 +0100 Subject: allow generic it_error params --- it_xml.class | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'it_xml.class') diff --git a/it_xml.class b/it_xml.class index 2a138d7..24970ba 100644 --- a/it_xml.class +++ b/it_xml.class @@ -26,7 +26,8 @@ class it_xml * @param $xmldata XML string or filehandle (result from fopen) to parse * @param $p associative array * @param $p['forcearray'] xml tags to ALWAYS return as array - * @param $p['safety'] 2 causes program abort with invalid xml, 1 (default) causes error report, 0 just returns false + * @param $p['safety'] OBSOLETE, see it_error. (0 = ignore errs, 1 = report errs, 2 = abort on errs) + * @param $p['it_error'] Parameters for it_errors on parsing problems * @param $p['encoding'] Output character encoding (utf-8, iso-8859-1 or us-ascii, default: ini_get('default_charset') * @param $p['prefix'] Optional prefix for class names * @param $p['lowercase'] Lowercase all tag and attribute names @@ -53,7 +54,8 @@ static function create($xmldata, $p = array()) function from_xml($xmldata, $p) { - $this->_p = $p + array('encoding' => ini_get('default_charset'), 'safety' => 1); + $p += ['encoding' => ini_get('default_charset'), 'it_error' => !$p['safety'] ? false : ($p['safety'] == 2 ? ['fatal' => true] : [])]; + $this->_p = $p; $this->_arrayforce = array_flip((array)$this->_p['forcearray']); $this->_stack = array(); unset($this->error); @@ -94,16 +96,13 @@ function from_xml($xmldata, $p) if ($this->error) { - if ($this->_p['safety'] >= 2) - it::fatal(array('title' => $this->error, 'body' => $xmlorig)); - else if ($this->_p['safety'] >= 1) - it::error(array('title' => $this->error, 'body' => $xmlorig)); + it::error((array)$p['it_error'] + ['title' => $this->error, 'body' => $xmlorig]); if ($this->_p['factory']) $GLOBALS['IT_XML_ERROR'] = $this->error; } - unset($this->_arrayforce, $this->_p['safety'], $this->_p['factory'], $this->_stack); + unset($this->_arrayforce, $this->_p['safety'], $this->_p['it_error'], $this->_p['factory'], $this->_stack); xml_parser_free($parser); return empty($this->error); -- cgit v1.2.3