Final Class Yiisoft\Files\PathMatcher\PathPattern
| Inheritance | Yiisoft\Files\PathMatcher\PathPattern |
|---|---|
| Implements | Yiisoft\Files\PathMatcher\PathMatcherInterface |
A shell path pattern to match against. Based on {@see WildcardPattern}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Files\PathMatcher\PathPattern | |
| caseSensitive() | Make pattern case sensitive. | Yiisoft\Files\PathMatcher\PathPattern |
| match() | Checks if the passed path would match the given shell path pattern. | Yiisoft\Files\PathMatcher\PathPattern |
| onlyDirectories() | Skip matching if path is not directory or directory does no exist. | Yiisoft\Files\PathMatcher\PathPattern |
| onlyFiles() | If path is not file or file not exists skip matching. | Yiisoft\Files\PathMatcher\PathPattern |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DIRECTORIES | 2 | Yiisoft\Files\PathMatcher\PathPattern | |
| FILES | 1 | Yiisoft\Files\PathMatcher\PathPattern |
Method Details
| public mixed __construct ( string $pattern ) | ||
| $pattern | string |
The path pattern to match against. |
public function __construct(string $pattern)
{
$this->pattern = (new WildcardPattern($pattern))->ignoreCase();
}
Make pattern case sensitive.
| public self caseSensitive ( ) |
public function caseSensitive(): self
{
$new = clone $this;
$new->pattern = $this->pattern->ignoreCase(false);
return $new;
}
Checks if the passed path would match the given shell path pattern.
If need match only files and path is directory or conversely then matching skipped and returned null.
| public boolean|null match ( string $path ) | ||
| $path | string |
The tested path. |
| return | boolean|null |
Whether the path matches pattern or not, |
|---|---|---|
public function match(string $path): ?bool
{
$path = str_replace('\\', '/', $path);
if (
($this->matchOnly === self::FILES && is_dir($path)) ||
($this->matchOnly === self::DIRECTORIES && is_file($path))
) {
return null;
}
return $this->pattern->match($path);
}
Skip matching if path is not directory or directory does no exist.
| public self onlyDirectories ( ) |
public function onlyDirectories(): self
{
$new = clone $this;
$new->matchOnly = self::DIRECTORIES;
return $new;
}
If path is not file or file not exists skip matching.
| public self onlyFiles ( ) |
public function onlyFiles(): self
{
$new = clone $this;
$new->matchOnly = self::FILES;
return $new;
}
Signup or Login in order to comment.