|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This software package is licensed under AGPL, Commercial license. |
|
5
|
|
|
* |
|
6
|
|
|
* @package maslosoft/addendum |
|
7
|
|
|
* @licence AGPL, Commercial |
|
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes) |
|
9
|
|
|
* @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes) |
|
10
|
|
|
* @copyright Copyright (c) Jan Suchal (Original version, builder, parser) |
|
11
|
|
|
* @link https://maslosoft.com/addendum/ - maslosoft addendum |
|
12
|
|
|
* @link https://code.google.com/p/addendum/ - original addendum project |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Maslosoft\Addendum\Exceptions; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
use Exception; |
|
19
|
|
|
use Throwable; |
|
20
|
|
|
|
|
21
|
|
|
class MatcherException extends Exception |
|
22
|
|
|
{ |
|
23
|
|
|
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
24
|
|
|
{ |
|
25
|
|
|
$message .= $this->errorToText($code, $message); |
|
26
|
|
|
parent::__construct($message, $code, $previous); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
private function errorToText($errorCode, $errorMessage) |
|
30
|
|
|
{ |
|
31
|
|
|
static $messages; |
|
32
|
|
|
|
|
33
|
|
|
if (!isset($errorMessage)) |
|
34
|
|
|
{ |
|
35
|
|
|
$messages = array(); |
|
36
|
|
|
$constants = get_defined_constants(true); |
|
37
|
|
|
foreach ($constants['pcre'] as $name => $code) |
|
38
|
|
|
{ |
|
39
|
|
|
if (preg_match('/_ERROR$/', $name)) |
|
40
|
|
|
{ |
|
41
|
|
|
$messages[$code] = $name; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return array_key_exists($errorCode, $messages)? $messages[$errorCode] : NULL; |
|
47
|
|
|
} |
|
48
|
|
|
} |