0 follower

Final Class Yiisoft\Files\PathMatcher\PathPattern

InheritanceYiisoft\Files\PathMatcher\PathPattern
ImplementsYiisoft\Files\PathMatcher\PathMatcherInterface

A shell path pattern to match against. Based on {@see WildcardPattern}.

Public Methods

Hide inherited 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

Hide inherited constants

Constant Value Description Defined By
DIRECTORIES 2 Yiisoft\Files\PathMatcher\PathPattern
FILES 1 Yiisoft\Files\PathMatcher\PathPattern

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $pattern )
$pattern string

The path pattern to match against.

                public function __construct(string $pattern)
{
    $this->pattern = (new WildcardPattern($pattern))->ignoreCase();
}

            
caseSensitive() public method

Make pattern case sensitive.

public self caseSensitive ( )

                public function caseSensitive(): self
{
    $new = clone $this;
    $new->pattern = $this->pattern->ignoreCase(false);
    return $new;
}

            
match() public method

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, null if matching skipped.

                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);
}

            
onlyDirectories() public method

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;
}

            
onlyFiles() public method

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;
}