2018-04-17 02:11:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2024-01-12 05:08:24 +00:00
|
|
|
$operators = ['not', '!', 'or', '||', '&&', 'and', '|', '^', '&', '==', '===', '!=', '!==', '<', '>', '>=', '<=', 'not in', 'in', '..', '+', '-', '~', '*', '/', '%', 'matches', '**'];
|
2018-04-17 02:11:51 +00:00
|
|
|
$operators = array_combine($operators, array_map('strlen', $operators));
|
|
|
|
arsort($operators);
|
|
|
|
|
2024-01-12 05:08:24 +00:00
|
|
|
$regex = [];
|
2018-04-17 02:11:51 +00:00
|
|
|
foreach ($operators as $operator => $length) {
|
2024-01-12 05:08:24 +00:00
|
|
|
// Collisions of character operators:
|
|
|
|
// - an operator that begins with a character must have a space or a parenthesis before or starting at the beginning of a string
|
|
|
|
// - an operator that ends with a character must be followed by a whitespace or a parenthesis
|
|
|
|
$regex[] =
|
|
|
|
(ctype_alpha($operator[0]) ? '(?<=^|[\s(])' : '')
|
|
|
|
.preg_quote($operator, '/')
|
|
|
|
.(ctype_alpha($operator[$length - 1]) ? '(?=[\s(])' : '');
|
2018-04-17 02:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '/'.implode('|', $regex).'/A';
|