CachedCollection.php 518 B

123456789101112131415161718192021
  1. <?php
  2. namespace Grav\Common\GPM\Common;
  3. use Grav\Common\Iterator;
  4. class CachedCollection extends Iterator {
  5. protected static $cache;
  6. public function __construct($items)
  7. {
  8. // local cache to speed things up
  9. if (!isset(self::$cache[get_called_class().__METHOD__])) {
  10. self::$cache[get_called_class().__METHOD__] = $items;
  11. }
  12. foreach (self::$cache[get_called_class().__METHOD__] as $name => $item) {
  13. $this->append([$name => $item]);
  14. }
  15. }
  16. }