Annotation of embedaddon/php/ext/spl/examples/findfile.inc, revision 1.1
1.1 ! misho 1: <?php
! 2:
! 3: /** @file findfile.inc
! 4: * @ingroup Examples
! 5: * @brief class FindFile
! 6: * @author Marcus Boerger
! 7: * @date 2003 - 2005
! 8: *
! 9: * SPL - Standard PHP Library
! 10: */
! 11:
! 12: if (!class_exists("FindFile", false)) require_once("findfile.inc");
! 13: if (!class_exists("AppendIterator", false)) require_once("appenditerator.inc");
! 14:
! 15: /** @ingroup Examples
! 16: * @brief Base class to find files
! 17: * @author Marcus Boerger
! 18: * @version 1.1
! 19: *
! 20: */
! 21: class FindFile extends FilterIterator
! 22: {
! 23: /** @internal filename to find */
! 24: private $file;
! 25:
! 26: /** Construct from path and filename
! 27: *
! 28: * @param $path the directory to search in
! 29: * If path contains ';' then this parameter is split and every
! 30: * part of it is used as separate directory.
! 31: * @param $file the name of the files to search fro
! 32: */
! 33: function __construct($path, $file)
! 34: {
! 35: $this->file = $file;
! 36: $list = split(PATH_SEPARATOR, $path);
! 37: if (count($list) <= 1) {
! 38: parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
! 39: } else {
! 40: $it = new AppendIterator();
! 41: foreach($list as $path) {
! 42: $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
! 43: }
! 44: parent::__construct($it);
! 45: }
! 46: }
! 47:
! 48: /** @return whether the current file matches the given filename
! 49: */
! 50: function accept()
! 51: {
! 52: return !strcmp($this->current(), $this->file);
! 53: }
! 54:
! 55: /** @return the filename to search for.
! 56: * @note This may be overloaded and contain a regular expression for an
! 57: * extended class that uses regular expressions to search.
! 58: */
! 59: function getSearch()
! 60: {
! 61: return $this->file;
! 62: }
! 63: }
! 64:
! 65: ?>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>