ColumnCache.php 909 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Michel\PaperORM\Cache;
  3. use Michel\PaperORM\Mapping\Column\Column;
  4. final class ColumnCache
  5. {
  6. private static ?ColumnCache $instance = null;
  7. private array $data = [];
  8. public static function getInstance(): self
  9. {
  10. if (self::$instance === null) {
  11. self::$instance = new self();
  12. }
  13. return self::$instance;
  14. }
  15. public function set(string $key, array $columns)
  16. {
  17. foreach ($columns as $column) {
  18. if (!$column instanceof Column) {
  19. throw new \InvalidArgumentException('All values in the array must be instances of Column.');
  20. }
  21. }
  22. $this->data[$key] = $columns;
  23. }
  24. public function get(string $key): array
  25. {
  26. if (isset($this->data[$key])) {
  27. return $this->data[$key];
  28. }
  29. return [];
  30. }
  31. }