diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/spl/examples/findfile.inc | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/spl/examples/findfile.inc')
-rw-r--r-- | ext/spl/examples/findfile.inc | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/ext/spl/examples/findfile.inc b/ext/spl/examples/findfile.inc new file mode 100644 index 0000000..02ab792 --- /dev/null +++ b/ext/spl/examples/findfile.inc @@ -0,0 +1,65 @@ +<?php + +/** @file findfile.inc + * @ingroup Examples + * @brief class FindFile + * @author Marcus Boerger + * @date 2003 - 2005 + * + * SPL - Standard PHP Library + */ + +if (!class_exists("FindFile", false)) require_once("findfile.inc"); +if (!class_exists("AppendIterator", false)) require_once("appenditerator.inc"); + +/** @ingroup Examples + * @brief Base class to find files + * @author Marcus Boerger + * @version 1.1 + * + */ +class FindFile extends FilterIterator +{ + /** @internal filename to find */ + private $file; + + /** Construct from path and filename + * + * @param $path the directory to search in + * If path contains ';' then this parameter is split and every + * part of it is used as separate directory. + * @param $file the name of the files to search fro + */ + function __construct($path, $file) + { + $this->file = $file; + $list = split(PATH_SEPARATOR, $path); + if (count($list) <= 1) { + parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); + } else { + $it = new AppendIterator(); + foreach($list as $path) { + $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); + } + parent::__construct($it); + } + } + + /** @return whether the current file matches the given filename + */ + function accept() + { + return !strcmp($this->current(), $this->file); + } + + /** @return the filename to search for. + * @note This may be overloaded and contain a regular expression for an + * extended class that uses regular expressions to search. + */ + function getSearch() + { + return $this->file; + } +} + +?>
\ No newline at end of file |