mirror of
https://github.com/stan220/WildcardEventDispatcher.git
synced 2026-09-08 15:28:37 +00:00
Handle preg_quote changes for PHP 7.3 (#14)
* Add PHP 7.3 to Travis * Prepare preg_replace() replacements by PHP version PHP 7.3+ requires the pattern to expect preg_quote() to escape `#` characters in the event pattern.
This commit is contained in:
@@ -9,6 +9,7 @@ php:
|
|||||||
- 7.0
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
- 7.2
|
- 7.2
|
||||||
|
- 7.3
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
|
|||||||
@@ -12,18 +12,7 @@ class ListenerPattern
|
|||||||
protected $priority;
|
protected $priority;
|
||||||
protected $regex;
|
protected $regex;
|
||||||
|
|
||||||
private static $replacements = array(
|
private static $replacements;
|
||||||
// Trailing single-wildcard with separator prefix
|
|
||||||
'/\\\\\.\\\\\*$/' => '(?:\.\w+)?',
|
|
||||||
// Single-wildcard with separator prefix
|
|
||||||
'/\\\\\.\\\\\*/' => '(?:\.\w+)',
|
|
||||||
// Single-wildcard without separator prefix
|
|
||||||
'/(?<!\\\\\.)\\\\\*/' => '(?:\w+)',
|
|
||||||
// Multi-wildcard with separator prefix
|
|
||||||
'/\\\\\.#/' => '(?:\.\w+)*',
|
|
||||||
// Multi-wildcard without separator prefix
|
|
||||||
'/(?<!\\\\\.)#/' => '(?:|\w+(?:\.\w+)*)',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -110,10 +99,52 @@ class ListenerPattern
|
|||||||
*/
|
*/
|
||||||
private function createRegex($eventPattern)
|
private function createRegex($eventPattern)
|
||||||
{
|
{
|
||||||
|
$replacements = self::getReplacements();
|
||||||
|
|
||||||
return sprintf('/^%s$/', preg_replace(
|
return sprintf('/^%s$/', preg_replace(
|
||||||
array_keys(self::$replacements),
|
array_keys($replacements),
|
||||||
array_values(self::$replacements),
|
array_values($replacements),
|
||||||
preg_quote($eventPattern, '/')
|
preg_quote($eventPattern, '/')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns preg_replace() replacements for preparing the event pattern.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function getReplacements()
|
||||||
|
{
|
||||||
|
if (null !== self::$replacements) {
|
||||||
|
return self::$replacements;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$replacements = array(
|
||||||
|
// Trailing single-wildcard with separator prefix
|
||||||
|
'/\\\\\.\\\\\*$/' => '(?:\.\w+)?',
|
||||||
|
// Single-wildcard with separator prefix
|
||||||
|
'/\\\\\.\\\\\*/' => '(?:\.\w+)',
|
||||||
|
// Single-wildcard without separator prefix
|
||||||
|
'/(?<!\\\\\.)\\\\\*/' => '(?:\w+)',
|
||||||
|
);
|
||||||
|
|
||||||
|
// preg_quote() escapes `#` in PHP 7.3+
|
||||||
|
if (PHP_VERSION_ID >= 70300) {
|
||||||
|
self::$replacements += array(
|
||||||
|
// Multi-wildcard with separator prefix
|
||||||
|
'/\\\\\.\\\\\#/' => '(?:\.\w+)*',
|
||||||
|
// Multi-wildcard without separator prefix
|
||||||
|
'/(?<!\\\\\.)\\\\\#/' => '(?:|\w+(?:\.\w+)*)',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
self::$replacements += array(
|
||||||
|
// Multi-wildcard with separator prefix
|
||||||
|
'/\\\\\.#/' => '(?:\.\w+)*',
|
||||||
|
// Multi-wildcard without separator prefix
|
||||||
|
'/(?<!\\\\\.)#/' => '(?:|\w+(?:\.\w+)*)',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$replacements;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user