CachedCollection.php 713 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * @package Grav\Common\GPM
  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\GPM\Common;
  9. use Grav\Common\Iterator;
  10. class CachedCollection extends Iterator
  11. {
  12. protected static $cache;
  13. public function __construct($items)
  14. {
  15. parent::__construct();
  16. $method = static::class . __METHOD__;
  17. // local cache to speed things up
  18. if (!isset(self::$cache[$method])) {
  19. self::$cache[$method] = $items;
  20. }
  21. foreach (self::$cache[$method] as $name => $item) {
  22. $this->append([$name => $item]);
  23. }
  24. }
  25. }