|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of ocubom/twig-svg-extension |
|
5
|
|
|
* |
|
6
|
|
|
* © Oscar Cubo Medina <https://ocubom.github.io> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ocubom\Twig\Extension\Svg\Exception; |
|
13
|
|
|
|
|
14
|
|
|
class Html5ParseException extends ParseException |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @param string|\SplFileInfo $source |
|
18
|
|
|
*/ |
|
19
|
1 |
|
public function __construct(string $message, $source = null, int $line = -1, int $col = -1, int $code = 0, \Throwable $previous = null) |
|
20
|
|
|
{ |
|
21
|
1 |
|
if (preg_match('@Line (\d+), Col (\d+): (.+)$@Uis', $message, $matches)) { |
|
22
|
1 |
|
$message = $matches[3]; |
|
23
|
1 |
|
$line = intval($matches[1]); |
|
24
|
1 |
|
$col = intval($matches[2]); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
$message = rtrim($message, " \n\r\t\v\x00.:"); |
|
28
|
1 |
|
$snippet = ''; |
|
29
|
|
|
|
|
30
|
1 |
|
if ($source instanceof \SplFileInfo) { |
|
31
|
|
|
$message .= sprintf(' in %s', (string) $source); // @codeCoverageIgnore |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
$sep = 'at'; |
|
35
|
1 |
|
if ($line >= 0) { |
|
36
|
1 |
|
$message .= sprintf(' %s line %d', $sep, $line + 1); |
|
37
|
1 |
|
$sep = 'and'; |
|
38
|
|
|
|
|
39
|
1 |
|
$snippet = preg_split( |
|
40
|
1 |
|
'@\s*[\n\r]\s*@', |
|
41
|
1 |
|
($source instanceof \SplFileInfo ? file_get_contents((string) $source) : $source) ?? '' |
|
42
|
1 |
|
); |
|
43
|
|
|
|
|
44
|
1 |
|
$snippet = $snippet[$line] ?? ''; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
if ($col >= 0) { |
|
48
|
1 |
|
$message .= sprintf(' %s column %d', $sep, $col + 1); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
if (!empty($snippet)) { |
|
52
|
1 |
|
$message .= sprintf(' (near "%s")', $snippet); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
parent::__construct($message.'.', $code, $previous); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|