Automattic\WooCommerce\Vendor\Pelago\Emogrifier\Utilities

Preg::logOrThrowPregLastErrorprivateWC 1.0

Obtains the name of the error constant for preg_last_error (based on code posted at {@see https://www.php.net/manual/en/function.preg-last-error.php#124124}) and puts it into an error message which is either passed to trigger_error or used in the exception which is thrown (depending on the $throwExceptions property).

Method of the class: Preg{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->logOrThrowPregLastError(): void;

Preg::logOrThrowPregLastError() code WC 10.5.0

private function logOrThrowPregLastError(): void
{
    $pcreConstants = \get_defined_constants(true)['pcre'];
    $pcreErrorConstantNames = \array_flip(\array_filter(
        $pcreConstants,
        static function (string $key): bool {
            return \substr($key, -6) === '_ERROR';
        },
        ARRAY_FILTER_USE_KEY
    ));

    $pregLastError = \preg_last_error();
    $message = 'PCRE regex execution error `' . (string) ($pcreErrorConstantNames[$pregLastError] ?? $pregLastError)
        . '`';

    if ($this->throwExceptions) {
        throw new \RuntimeException($message, 1592870147);
    }
    \trigger_error($message);
}