Comparator
3 years ago
Exception
3 years ago
Iterator
3 years ago
Finder.php
4 years ago
Gitignore.php
4 years ago
Glob.php
4 years ago
SplFileInfo.php
4 years ago
index.php
3 years ago
Glob.php
67 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Finder; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class Glob |
| 5 | { |
| 6 | public static function toRegex($glob, $strictLeadingDot = \true, $strictWildcardSlash = \true, $delimiter = '#') |
| 7 | { |
| 8 | $firstByte = \true; |
| 9 | $escaping = \false; |
| 10 | $inCurlies = 0; |
| 11 | $regex = ''; |
| 12 | $sizeGlob = \strlen($glob); |
| 13 | for ($i = 0; $i < $sizeGlob; ++$i) { |
| 14 | $car = $glob[$i]; |
| 15 | if ($firstByte && $strictLeadingDot && '.' !== $car) { |
| 16 | $regex .= '(?=[^\\.])'; |
| 17 | } |
| 18 | $firstByte = '/' === $car; |
| 19 | if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1] . $glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) { |
| 20 | $car = '[^/]++/'; |
| 21 | if (!isset($glob[$i + 3])) { |
| 22 | $car .= '?'; |
| 23 | } |
| 24 | if ($strictLeadingDot) { |
| 25 | $car = '(?=[^\\.])' . $car; |
| 26 | } |
| 27 | $car = '/(?:' . $car . ')*'; |
| 28 | $i += 2 + isset($glob[$i + 3]); |
| 29 | if ('/' === $delimiter) { |
| 30 | $car = \str_replace('/', '\\/', $car); |
| 31 | } |
| 32 | } |
| 33 | if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) { |
| 34 | $regex .= "\\{$car}"; |
| 35 | } elseif ('*' === $car) { |
| 36 | $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*'); |
| 37 | } elseif ('?' === $car) { |
| 38 | $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.'); |
| 39 | } elseif ('{' === $car) { |
| 40 | $regex .= $escaping ? '\\{' : '('; |
| 41 | if (!$escaping) { |
| 42 | ++$inCurlies; |
| 43 | } |
| 44 | } elseif ('}' === $car && $inCurlies) { |
| 45 | $regex .= $escaping ? '}' : ')'; |
| 46 | if (!$escaping) { |
| 47 | --$inCurlies; |
| 48 | } |
| 49 | } elseif (',' === $car && $inCurlies) { |
| 50 | $regex .= $escaping ? ',' : '|'; |
| 51 | } elseif ('\\' === $car) { |
| 52 | if ($escaping) { |
| 53 | $regex .= '\\\\'; |
| 54 | $escaping = \false; |
| 55 | } else { |
| 56 | $escaping = \true; |
| 57 | } |
| 58 | continue; |
| 59 | } else { |
| 60 | $regex .= $car; |
| 61 | } |
| 62 | $escaping = \false; |
| 63 | } |
| 64 | return $delimiter . '^' . $regex . '$' . $delimiter; |
| 65 | } |
| 66 | } |
| 67 |