-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibXml.php
More file actions
40 lines (29 loc) · 920 Bytes
/
LibXml.php
File metadata and controls
40 lines (29 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace VaclavVanik\DomLoader\Exception;
use LibXMLError;
use RuntimeException;
use function sprintf;
use function trim;
final class LibXml extends RuntimeException implements Exception
{
/** @var LibXMLError */
private $libXmlError;
private function __construct(LibXMLError $libXmlError, string $message)
{
$this->libXmlError = $libXmlError;
parent::__construct($message);
}
public static function fromLibXMLError(LibXMLError $error): self
{
$toErrorMessage = static function (LibXMLError $error): string {
$format = '%s on line: %d, column: %d';
return sprintf($format, trim($error->message), $error->line, $error->column);
};
return new self($error, $toErrorMessage($error));
}
public function getLibXmlError(): LibXMLError
{
return $this->libXmlError;
}
}