/** * Construct a phar data adapter. If the path isn't a file or if the path * isn't a file that phardata understands, an exception will be thrown. * * @param string $path * @throws FinderException if $path is not a file * @throws UnexpectedValueException if $path isn't a phardata file. */ public function __construct($path) { $fileInfo = new SplFileInfo($path); if (!$fileInfo->isFile()) { throw new FinderException("{$path} is not a file."); } parent::__construct(self::PHAR_PREFIX . $fileInfo->getRealPath()); }
/** * Construct a directory adapter. If the $path isn't a directory, and * exception will be thrown. * * @param string $path * @throws FinderException */ public function __construct($path) { $fileInfo = new SplFileInfo($path); if (!$fileInfo->isDir()) { throw new FinderException("{$path} is not a directory."); } parent::__construct($fileInfo->getRealPath()); }
/** * Examine each file and directory beneath the path, and return an SplFileInfo * object for each one. The depth will be limited to $depth levels, if provided. * * The options array may be used to limit the depth of the recursion: * * depth = -1 is the default, and sets no limit on the recursion. * depth = 0 will return no results * depth = 1 will return results for the top level directory. * depth = 2 will return results for the top two directories. * etc. * * The options may also be used to exclude directories * * exclude = array('foo', 'bar') will prevent the finder * from looking in directories called foo or bar. * * @param Closure $callback * @param array $options * @return SplFileInfo[] */ public function find(Closure $callback = null, $options = array()) { if ($callback === null) { $callback = function (SplFileInfo $fileInfo) { return true; }; } if (!array_key_exists('depth', $options)) { $options['depth'] = -1; } if (!array_key_exists('exclude', $options)) { $options['exclude'] = array(); } $iterator = $this->adapter->getRoot(); $matches = $this->recurse($callback, $iterator, $options); return $matches; }