findfile.inc 1.6 KB

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