PHP 클래스 Webmozart\Glob\Glob

This class implements an Ant-like version of PHP's glob() function. The wildcard "*" matches any number of characters except directory separators. The double wildcard "**" matches any number of characters, including directory separators. Use {@link glob()} to glob the filesystem for paths: php foreach (Glob::glob('/project/**.twig') as $path) { do something... } Use {@link match()} to match a file path against a glob: php if (Glob::match('/project/views/index.html.twig', '/project/**.twig')) { path matches } You can also filter an array of paths for all paths that match your glob with {@link filter()}: php $filteredPaths = Glob::filter($paths, '/project/**.twig'); Internally, the methods described above convert the glob into a regular expression that is then matched against the matched paths. If you need to match many paths against the same glob, you should convert the glob manually and use {@link preg_match()} to test the paths: php $staticPrefix = Glob::getStaticPrefix('/project/**.twig'); $regEx = Glob::toRegEx('/project/**.twig'); if (0 !== strpos($path, $staticPrefix)) { no match } if (!preg_match($regEx, $path)) { no match } The method {@link getStaticPrefix()} returns the part of the glob up to the first wildcard "*". You should always test whether a path has this prefix before calling the much more expensive {@link preg_match()}.
부터: 1.0
저자: Bernhard Schussek ([email protected])
파일 보기 프로젝트 열기: webmozart/glob 1 사용 예제들

공개 메소드들

메소드 설명
filter ( array $paths, string $glob, integer $flags = self::FILTER_VALUE ) : string[] Filters an array for paths matching a glob.
getBasePath ( string $glob, integer $flags ) : string Returns the base path of a glob.
getStaticPrefix ( string $glob, integer $flags ) : string Returns the static prefix of a glob.
glob ( string $glob, integer $flags ) : string[] Globs the file system paths matching the glob.
isDynamic ( string $glob ) : boolean Returns whether the glob contains a dynamic part.
match ( string $path, string $glob, integer $flags ) : boolean Matches a path against a glob.
toRegEx ( string $glob, integer $flags, $delimiter = '~' ) : string Converts a glob to a regular expression.

비공개 메소드들

메소드 설명
__construct ( )

메소드 상세

filter() 공개 정적인 메소드

The filtered array is returned. This array preserves the keys of the passed array. php $filteredPaths = Glob::filter($paths, '/project/**.twig');
public static filter ( array $paths, string $glob, integer $flags = self::FILTER_VALUE ) : string[]
$paths array A list of paths.
$glob string The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method.
$flags integer A bitwise combination of the flag constants in this class.
리턴 string[] The paths matching the glob indexed by their original keys.

getBasePath() 공개 정적인 메소드

This method returns the most specific directory that contains all files matched by the glob. If this directory does not exist on the file system, it's not necessary to execute the glob algorithm. More specifically, the "base path" is the longest path trailed by a "/" on the left of the first wildcard "*". If the glob does not contain wildcards, the directory name of the glob is returned. php Glob::getBasePath('/css/*.css'); => /css Glob::getBasePath('/css/style.css'); => /css Glob::getBasePath('/css/st*.css'); => /css Glob::getBasePath('/*.css'); => /
public static getBasePath ( string $glob, integer $flags ) : string
$glob string The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method.
$flags integer A bitwise combination of the flag constants in this class.
리턴 string The base path of the glob.

getStaticPrefix() 공개 정적인 메소드

The "static prefix" is the part of the glob up to the first wildcard "*". If the glob does not contain wildcards, the full glob is returned.
public static getStaticPrefix ( string $glob, integer $flags ) : string
$glob string The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method.
$flags integer A bitwise combination of the flag constants in this class.
리턴 string The static prefix of the glob.

glob() 공개 정적인 메소드

The glob may contain the wildcard "*". This wildcard matches any number of characters, *including* directory separators. php foreach (Glob::glob('/project/**.twig') as $path) { do something... }
public static glob ( string $glob, integer $flags ) : string[]
$glob string The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method.
$flags integer A bitwise combination of the flag constants in this class.
리턴 string[] The matching paths. The keys of the array are incrementing integers.

isDynamic() 공개 정적인 메소드

The glob contains a dynamic part if it contains an unescaped "*" or "{" character.
public static isDynamic ( string $glob ) : boolean
$glob string The glob to test.
리턴 boolean Returns `true` if the glob contains a dynamic part and `false` otherwise.

match() 공개 정적인 메소드

php if (Glob::match('/project/views/index.html.twig', '/project/**.twig')) { path matches }
public static match ( string $path, string $glob, integer $flags ) : boolean
$path string The path to match.
$glob string The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method.
$flags integer A bitwise combination of the flag constants in this class.
리턴 boolean Returns `true` if the path is matched by the glob.

toRegEx() 공개 정적인 메소드

Use this method if you need to match many paths against a glob: php $staticPrefix = Glob::getStaticPrefix('/project/**.twig'); $regEx = Glob::toRegEx('/project/**.twig'); if (0 !== strpos($path, $staticPrefix)) { no match } if (!preg_match($regEx, $path)) { no match } You should always test whether a path contains the static prefix of the glob returned by {@link getStaticPrefix()} to reduce the number of calls to the expensive {@link preg_match()}.
public static toRegEx ( string $glob, integer $flags, $delimiter = '~' ) : string
$glob string The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method.
$flags integer A bitwise combination of the flag constants in this class.
리턴 string The regular expression for matching the glob.