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
|
|
|
use Ocubom\Twig\Extension\Svg\Util\AggregatedExceptionTrait; |
15
|
|
|
|
16
|
|
|
use function BenTools\IterableFunctions\iterable_to_array; |
17
|
|
|
use function Ocubom\Twig\Extension\is_string; |
18
|
|
|
|
19
|
|
|
class LoaderException extends RuntimeException |
20
|
|
|
{ |
21
|
|
|
use AggregatedExceptionTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param \Throwable|iterable<\Throwable> $previous |
25
|
|
|
*/ |
26
|
6 |
|
public function __construct(string $ident, \ReflectionClass $loader = null, string $source = null, int $code = 0, $previous = null) |
27
|
|
|
{ |
28
|
6 |
|
if (is_iterable($previous)) { |
29
|
4 |
|
$previous = iterable_to_array(/* @scrutinizer ignore-type */ $previous, false); |
30
|
|
|
|
31
|
4 |
|
if (1 === count($previous)) { |
32
|
4 |
|
$previous = $previous[0]; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
6 |
|
if ($previous instanceof \Throwable) { |
37
|
4 |
|
$lines = explode("\n", $previous->getMessage()); |
38
|
4 |
|
$message = sprintf( |
39
|
4 |
|
'%s loading SVG for "%s"', |
40
|
4 |
|
rtrim($lines[0], " \n\r\t\v\x00.:"), |
41
|
4 |
|
$ident |
42
|
4 |
|
); |
43
|
|
|
|
44
|
4 |
|
if (is_string($source)) { |
45
|
|
|
$message .= sprintf(' on "%s"', $source); |
46
|
|
|
} |
47
|
|
|
|
48
|
4 |
|
if ($loader instanceof \ReflectionClass) { |
49
|
4 |
|
$message .= sprintf(' by "%s"', $loader->getShortName()); |
50
|
|
|
} |
51
|
|
|
|
52
|
4 |
|
if (count($lines) > 1) { |
53
|
|
|
$message .= ':'; |
54
|
|
|
$message .= implode("\n", array_slice($lines, 1)); |
55
|
|
|
} else { |
56
|
4 |
|
$message .= '.'; |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
6 |
|
$message = $loader instanceof \ReflectionClass |
60
|
6 |
|
? sprintf('"%s" cannot load SVG for "%s"', $loader->getShortName(), $ident) |
61
|
|
|
: sprintf('Unable to load SVG for "%s"', $ident); |
62
|
|
|
|
63
|
6 |
|
if (is_string($source)) { |
64
|
4 |
|
$message .= sprintf(' on "%s"', $source); |
65
|
|
|
} |
66
|
|
|
|
67
|
6 |
|
$message = $this->formatMessage($message, $previous); |
68
|
|
|
} |
69
|
|
|
|
70
|
6 |
|
parent::__construct($message, $code, $previous instanceof \Throwable ? $previous : null); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|