Class ContainsPathFilterIterator
Filters files based on whether their path contains or matches specific patterns.
Supports two types of patterns:
- String patterns: Uses substring matching (str_contains) for simple strings
- Regex patterns: Uses preg_match for patterns starting with /, #, or ~
Uses OR logic: accepts if any pattern matches. Always allows directories to enable recursive traversal.
Can be used to include or exclude files based on the $negate parameter:
- When $negate is false (default): includes files matching patterns
- When $negate is true: excludes files matching patterns
Property Summary
-
$regexPatterns protected
array<string>Regex patterns (pattern matching, normalized)
-
$stringPatterns protected
array<string>String patterns (substring matching, normalized)
Method Summary
-
__construct() public
-
accept() public
-
getChildren() public
Method Detail
__construct() ¶ public
__construct(RecursiveIterator<string, \SplFileInfo> $iterator, array<string> $patterns, bool $negate = false)
Parameters
-
RecursiveIterator<string, \SplFileInfo>$iterator The iterator to filter
-
array<string>$patterns Path patterns to match (string or regex)
-
bool$negate optional When true, inverts the filter (excludes matching paths)