Kahlan\Dir\Dir::scan PHP Method

scan() public static method

Scans one or many directories for files.
public static scan ( array | string $path, array $options = [] ) : array
$path array | string Path or paths to scan.
$options array Scanning options. Possible values are: -`'iterator'` _integer_ : The iterator mode. -`'skipDots'` _boolean_ : Keeps '.' and '..' if `true`. -`'leavesOnly'` _boolean_ : Keeps only leaves if `true`. -`'followSymlinks'` _boolean_ : Follows Symlinks if `true`. -`'recursive'` _boolean_ : Scans recursively if `true`. -`'include'` _string|array_: An array of includes. -`'exclude'` _string|array_: An array of excludes. -`'type'` _string|array_: An array of types.
return array
    public static function scan($path, $options = [])
    {
        $defaults = ['iterator' => RecursiveIteratorIterator::SELF_FIRST, 'skipDots' => true, 'leavesOnly' => false, 'followSymlinks' => true, 'recursive' => true];
        $options += $defaults;
        $paths = (array) $path;
        $dirFlags = static::_dirFlags($options);
        $iteratorFlags = static::_iteratorFlags($options);
        $result = [];
        foreach ($paths as $path) {
            $result = array_merge($result, static::_scan($path, $options, $dirFlags, $iteratorFlags));
        }
        return $result;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * The default `'load'` filter.
  */
 protected function _load()
 {
     return Filter::on($this, 'load', [], function ($chain) {
         $files = Dir::scan($this->args()->get('spec'), ['include' => $this->args()->get('pattern'), 'exclude' => '*/.*', 'type' => 'file']);
         foreach ($files as $file) {
             require $file;
         }
     });
 }
All Usage Examples Of Kahlan\Dir\Dir::scan