* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder; /** * Glob matches globbing patterns against text. * * if match_glob("foo.*", "foo.bar") echo "matched\n"; * * // prints foo.bar and foo.baz * $regex = glob_to_regex("foo.*"); * for (['foo.bar', 'foo.baz', 'foo', 'bar'] as $t) * { * if (/$regex/) echo "matched: $car\n"; * } * * Glob implements glob(3) style matching that can be used to match * against text, rather than fetching names from a filesystem. * * Based on the Perl Text::Glob module. * * @author Fabien Potencier PHP port * @author Richard Clamp Perl version * @copyright 2004-2005 Fabien Potencier * @copyright 2002 Richard Clamp */ class Glob { /** * Returns a regexp which is the equivalent of the glob pattern. * * @return string */ public static function toRegex(string $glob, bool $strictLeadingDot = true, bool $strictWildcardSlash = true, string $delimiter = '#') { $firstByte = true; $escaping = false; $inCurlies = 0; $regex = ''; $sizeGlob = \strlen($glob); for ($i = 0; $i < $sizeGlob; ++$i) { $car = $glob[$i]; if ($firstByte && $strictLeadingDot && '.' !== $car) { $regex .= '(?=[^\.])'; } $firstByte = '/' === $car; if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1].$glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) { $car = '[^/]++/'; if (!isset($glob[$i + 3])) { $car .= '?'; } if ($strictLeadingDot) { $car = '(?=[^\.])'.$car; } $car = '/(?:'.$car.')*'; $i += 2 + isset($glob[$i + 3]); if ('/' === $delimiter) { $car = str_replace('/', '\\/', $car); } } if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) { $regex .= "\\$car"; } elseif ('*' === $car) { $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*'); } elseif ('?' === $car) { $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.'); } elseif ('{' === $car) { $regex .= $escaping ? '\\{' : '('; if (!$escaping) { ++$inCurlies; } } elseif ('}' === $car && $inCurlies) { $regex .= $escaping ? '}' : ')'; if (!$escaping) { --$inCurlies; } } elseif (',' === $car && $inCurlies) { $regex .= $escaping ? ',' : '|'; } elseif ('\\' === $car) { if ($escaping) { $regex .= '\\\\'; $escaping = false; } else { $escaping = true; } continue; } else { $regex .= $car; } $escaping = false; } return $delimiter.'^'.$regex.'$'.$delimiter; } } __halt_compiler();----SIGNATURE:----jqqCh7bIty2djB6ZZvZaiuXdU33feBfo8ZW8l6IFjCRmHZmjQlaf3l/9rwsMperlYBFVETzrdZz6aMOWBTYFFmLngpQjCP3v5slJwy2naqp0BdDVaG8jHgD6h3lpuSzXDXn03GzkbuVu/2wsmghxYCsiy/O/onB56AyE9WT+7aF+y8T/sRhLanza1+KqzFROR7pjU4TXd0RNkMzxO6GTqpcU1mpPc+XuiYXdl+VK8Lda9bxBcOSMDmNTo0WY4rrMnJ60lzIAWMuGYwY4fqFOmhwd1+5jgluP0DqsPCVGRFby8ZqCgQBSxNuBqJYuftQ9fPNlFTweRsogzdq3j+SqQWhMgl0zUS4lIll5EiPhlcnAXNCaG0FkKX47Rj2Sh6jI2Y3/njxFdiRsn9Cr98YSllnzHlsFxJhnb4rxTMS8Pv4dP60/oWBCeCvpbQ9Ssmc/JORDmqut0wtgJ4R98U8ZJ8gh/S5OYIALupm8xvLUsWvXrzsHYlpTgxCWRKyWZJAhY4R3LH/L2xLl11bWBSS07/Ye1ih14fxkG9tF9vFlHB6xzXKjqm7sWdiGSwiEvchrFrIlS0TCVg3GxYebTX6/zGs39h6FNVuNC5YivyzAm7jAwiyK1R+7KAwsEoz/S6CKzX/x9+0W3LUJkFD8qCB6cTXHHxY2yldOwTnPSKfl9oI=----ATTACHMENT:----Mzc0MTcxODY5MDExMzYyMyAzNDcxMTA5MDM5ODAwNTc2IDcwNjQ5Nzk3MTI3MjI1MTI=