<?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.
*/
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 (array('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 <fabien@symfony.com> PHP port
* @author Richard Clamp <richardc@unixbeard.net> Perl version
* @copyright 2004-2005 Fabien Potencier <fabien@symfony.com>
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
*/
class Glob
{
/**
* Returns a regexp which is the equivalent of the glob pattern.
*
* @param string $glob The glob pattern
* @param bool $strictLeadingDot
* @param bool $strictWildcardSlash
* @param string $delimiter Optional delimiter
*
* @return string regex The regexp
*/
public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true, $delimiter = '#')
{
$firstByte = true;
$escaping = false;
$inCurlies = 0;
$regex = '';
$sizeGlob = strlen($glob);
for ($i = 0; $i < $sizeGlob; ++$i) {
$car = $glob[$i];
if ($firstByte) {
if ($strictLeadingDot && '.' !== $car) {
$regex .= '(?=[^\.])';
}
$firstByte = false;
}
if ('/' === $car) {
$firstByte = true;
}
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;
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| Adapter/ | 2016-11-07 15:54 | 27.34 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Comparator/ | 2016-11-07 15:54 | 5.96 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Exception/ | 2016-11-07 15:54 | 4.09 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Expression/ | 2016-11-07 15:54 | 12.32 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Iterator/ | 2016-11-07 15:54 | 27.7 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Shell/ | 2016-11-07 15:54 | 8.44 KB | 76129f60960:kunden | dxwrx-rx-r | |
| CHANGELOG.md | 2016-11-07 15:53 | 1.13 KB | 76129f60960:kunden | -xw-x----- | |
| Finder.php | 2016-11-07 15:53 | 24.85 KB | 76129f60960:kunden | -xw-x----- | |
| Glob.php | 2016-11-07 15:53 | 3.21 KB | 76129f60960:kunden | -xw-x----- | |
| LICENSE | 2016-11-07 15:53 | 1.04 KB | 76129f60960:kunden | -xw-x----- | |
| README.md | 2016-11-07 15:53 | 500 B | 76129f60960:kunden | -xw-x----- | |
| SplFileInfo.php | 2016-11-07 15:53 | 1.86 KB | 76129f60960:kunden | -xw-x----- | |
| phpunit.xml.dist | 2016-11-07 15:53 | 775 B | 76129f60960:kunden | -xw-x----- | |