RecursiveFolderFilterIterator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @package Grav\Common\Filesystem
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Filesystem;
  9. use Grav\Common\Grav;
  10. class RecursiveFolderFilterIterator extends \RecursiveFilterIterator
  11. {
  12. protected static $ignore_folders;
  13. /**
  14. * Create a RecursiveFilterIterator from a RecursiveIterator
  15. *
  16. * @param \RecursiveIterator $iterator
  17. * @param array $ignore_folders
  18. */
  19. public function __construct(\RecursiveIterator $iterator, $ignore_folders = [])
  20. {
  21. parent::__construct($iterator);
  22. if (empty($ignore_folders)) {
  23. $ignore_folders = Grav::instance()['config']->get('system.pages.ignore_folders');
  24. }
  25. $this::$ignore_folders = $ignore_folders;
  26. }
  27. /**
  28. * Check whether the current element of the iterator is acceptable
  29. *
  30. * @return bool true if the current element is acceptable, otherwise false.
  31. */
  32. public function accept()
  33. {
  34. /** @var \SplFileInfo $current */
  35. $current = $this->current();
  36. return $current->isDir() && !in_array($current->getFilename(), $this::$ignore_folders, true);
  37. }
  38. }