@@ -121,15 +121,16 @@ public function __construct(
121
121
* Retrieve array of xml errors
122
122
*
123
123
* @param string $errorFormat
124
+ * @param \DOMDocument|null $dom
124
125
* @return string[]
125
126
*/
126
- private static function getXmlErrors ($ errorFormat )
127
+ private static function getXmlErrors ($ errorFormat, $ dom = null )
127
128
{
128
129
$ errors = [];
129
130
$ validationErrors = libxml_get_errors ();
130
131
if (count ($ validationErrors )) {
131
132
foreach ($ validationErrors as $ error ) {
132
- $ errors [] = self ::_renderErrorMessage ($ error , $ errorFormat );
133
+ $ errors [] = self ::_renderErrorMessage ($ error , $ errorFormat, $ dom );
133
134
}
134
135
} else {
135
136
$ errors [] = 'Unknown validation error ' ;
@@ -380,7 +381,7 @@ public static function validateDomDocument(
380
381
try {
381
382
$ result = $ dom ->schemaValidate ($ schema );
382
383
if (!$ result ) {
383
- $ errors = self ::getXmlErrors ($ errorFormat );
384
+ $ errors = self ::getXmlErrors ($ errorFormat, $ dom );
384
385
}
385
386
} catch (\Exception $ exception ) {
386
387
$ errors = self ::getXmlErrors ($ errorFormat );
@@ -398,10 +399,11 @@ public static function validateDomDocument(
398
399
*
399
400
* @param \LibXMLError $errorInfo
400
401
* @param string $format
402
+ * @param \DOMDocument|null $dom
401
403
* @return string
402
404
* @throws \InvalidArgumentException
403
405
*/
404
- private static function _renderErrorMessage (\LibXMLError $ errorInfo , $ format )
406
+ private static function _renderErrorMessage (\LibXMLError $ errorInfo , $ format, $ dom = null )
405
407
{
406
408
$ result = $ format ;
407
409
foreach ($ errorInfo as $ field => $ value ) {
@@ -424,6 +426,14 @@ private static function _renderErrorMessage(\LibXMLError $errorInfo, $format)
424
426
}
425
427
}
426
428
}
429
+ if ($ dom ) {
430
+ $ xml = explode (PHP_EOL , $ dom ->saveXml ());
431
+ $ lines = array_slice ($ xml , max (0 , $ errorInfo ->line - 5 ), 10 , true );
432
+ $ result .= 'The xml was: ' .PHP_EOL ;
433
+ foreach ($ lines as $ lineNumber => $ line ) {
434
+ $ result .= $ lineNumber .': ' .$ line .PHP_EOL ;
435
+ }
436
+ }
427
437
return $ result ;
428
438
}
429
439
0 commit comments