diff --git a/src/Regex/Regex.php b/src/Regex/Regex.php index 3f13d69b..ead817fe 100644 --- a/src/Regex/Regex.php +++ b/src/Regex/Regex.php @@ -2,8 +2,6 @@ namespace Dotenv\Regex; -use PhpOption\Option; - class Regex { /** @@ -81,20 +79,23 @@ private static function pregAndWrap(callable $operation, $subject) */ private static function lookupError($code) { - return Option::fromValue(get_defined_constants(true)) - ->filter(function (array $consts) { - return isset($consts['pcre']) && defined('ARRAY_FILTER_USE_KEY'); - }) - ->map(function (array $consts) { - return array_filter($consts['pcre'], function ($msg) { - return substr($msg, -6) === '_ERROR'; - }, ARRAY_FILTER_USE_KEY); - }) - ->flatMap(function (array $errors) use ($code) { - return Option::fromValue( - array_search($code, $errors, true) - ); - }) - ->getOrElse('PREG_ERROR'); + if (defined('PREG_JIT_STACKLIMIT_ERROR') && $code === PREG_JIT_STACKLIMIT_ERROR) { + return 'JIT stack limit exhausted'; + } + + switch ($code) { + case PREG_INTERNAL_ERROR: + return 'Internal error'; + case PREG_BAD_UTF8_ERROR: + return 'Malformed UTF-8 characters, possibly incorrectly encoded'; + case PREG_BAD_UTF8_OFFSET_ERROR: + return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; + case PREG_BACKTRACK_LIMIT_ERROR: + return 'Backtrack limit exhausted'; + case PREG_RECURSION_LIMIT_ERROR: + return 'Recursion limit exhausted'; + default: + return 'Unknown error'; + } } }