|
2 | 2 |
|
3 | 3 | namespace Dotenv\Regex;
|
4 | 4 |
|
5 |
| -use PhpOption\Option; |
6 |
| - |
7 | 5 | class Regex
|
8 | 6 | {
|
9 | 7 | /**
|
@@ -81,20 +79,23 @@ private static function pregAndWrap(callable $operation, $subject)
|
81 | 79 | */
|
82 | 80 | private static function lookupError($code)
|
83 | 81 | {
|
84 |
| - return Option::fromValue(get_defined_constants(true)) |
85 |
| - ->filter(function (array $consts) { |
86 |
| - return isset($consts['pcre']) && defined('ARRAY_FILTER_USE_KEY'); |
87 |
| - }) |
88 |
| - ->map(function (array $consts) { |
89 |
| - return array_filter($consts['pcre'], function ($msg) { |
90 |
| - return substr($msg, -6) === '_ERROR'; |
91 |
| - }, ARRAY_FILTER_USE_KEY); |
92 |
| - }) |
93 |
| - ->flatMap(function (array $errors) use ($code) { |
94 |
| - return Option::fromValue( |
95 |
| - array_search($code, $errors, true) |
96 |
| - ); |
97 |
| - }) |
98 |
| - ->getOrElse('PREG_ERROR'); |
| 82 | + if (defined('PREG_JIT_STACKLIMIT_ERROR') && $code === PREG_JIT_STACKLIMIT_ERROR) { |
| 83 | + return 'JIT stack limit exhausted'; |
| 84 | + } |
| 85 | + |
| 86 | + switch ($code) { |
| 87 | + case PREG_INTERNAL_ERROR: |
| 88 | + return 'Internal error'; |
| 89 | + case PREG_BAD_UTF8_ERROR: |
| 90 | + return 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
| 91 | + case PREG_BAD_UTF8_OFFSET_ERROR: |
| 92 | + return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; |
| 93 | + case PREG_BACKTRACK_LIMIT_ERROR: |
| 94 | + return 'Backtrack limit exhausted'; |
| 95 | + case PREG_RECURSION_LIMIT_ERROR: |
| 96 | + return 'Recursion limit exhausted'; |
| 97 | + default: |
| 98 | + return 'Unknown error'; |
| 99 | + } |
99 | 100 | }
|
100 | 101 | }
|
0 commit comments