RecursiveActionIterator.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @package Grav\Framework\Acl
  4. *
  5. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Framework\Acl;
  9. use RecursiveIterator;
  10. use RocketTheme\Toolbox\ArrayTraits\Constructor;
  11. use RocketTheme\Toolbox\ArrayTraits\Countable;
  12. use RocketTheme\Toolbox\ArrayTraits\Iterator;
  13. /**
  14. * Class Action
  15. * @package Grav\Framework\Acl
  16. * @implements RecursiveIterator<string,Action>
  17. */
  18. class RecursiveActionIterator implements RecursiveIterator, \Countable
  19. {
  20. use Constructor, Iterator, Countable;
  21. public $items;
  22. /**
  23. * @see \Iterator::key()
  24. * @return string
  25. */
  26. #[\ReturnTypeWillChange]
  27. public function key()
  28. {
  29. /** @var Action $current */
  30. $current = $this->current();
  31. return $current->name;
  32. }
  33. /**
  34. * @see \RecursiveIterator::hasChildren()
  35. * @return bool
  36. */
  37. public function hasChildren(): bool
  38. {
  39. /** @var Action $current */
  40. $current = $this->current();
  41. return $current->hasChildren();
  42. }
  43. /**
  44. * @see \RecursiveIterator::getChildren()
  45. * @return RecursiveActionIterator
  46. */
  47. public function getChildren(): self
  48. {
  49. /** @var Action $current */
  50. $current = $this->current();
  51. return new static($current->getChildren());
  52. }
  53. }