tutorial_example_04.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. require 'tutorial_autoload.php';
  3. class myProgressFinder
  4. {
  5. static public function findRecursiveCallback( ezcBaseFileFindContext $context, $sourceDir, $fileName, $fileInfo )
  6. {
  7. // ignore if we have a directory, but do print a "." and sleep for
  8. // extra demo time
  9. if ( $fileInfo['mode'] & 0x4000 )
  10. {
  11. echo ".";
  12. usleep( 100000 );
  13. return;
  14. }
  15. // update the statistics
  16. $context->elements[] = $sourceDir . DIRECTORY_SEPARATOR . $fileName;
  17. $context->count++;
  18. $context->size += $fileInfo['size'];
  19. }
  20. static public function findRecursive( $sourceDir, array $includeFilters = array(), array $excludeFilters = array() )
  21. {
  22. // create the context, and then start walking over the array
  23. $context = new ezcBaseFileFindContext;
  24. ezcBaseFile::walkRecursive( $sourceDir, $includeFilters, $excludeFilters,
  25. array( 'myProgressFinder', 'findRecursiveCallback' ), $context );
  26. // collect the statistics (which we don't do anything with in this example)
  27. $statistics['size'] = $context->size;
  28. $statistics['count'] = $context->count;
  29. // return the found and pattern-matched files
  30. sort( $context->elements );
  31. return $context->elements;
  32. }
  33. }
  34. $files = myProgressFinder::findRecursive( dirname( __FILE__ ) );
  35. var_dump( $files );
  36. ?>