CategoriesContainer.php 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: lcdee
  5. * Date: 31.05.2017
  6. * Time: 12:57
  7. */
  8. namespace AlexLcDee\RegistryContainer;
  9. class CategoriesContainer
  10. {
  11. /**
  12. * @var ItemsContainer[]
  13. */
  14. private $data = [];
  15. /**
  16. * Add new category in container
  17. * @param string $key
  18. * @param ItemsContainer $value
  19. */
  20. public function add(string $key, ItemsContainer $value)
  21. {
  22. $this->data[$key] = $value;
  23. }
  24. /**
  25. * Check if container has category
  26. * @param string $key
  27. * @return bool
  28. */
  29. public function has(string $key)
  30. {
  31. return isset($this->data[$key]);
  32. }
  33. /**
  34. * Get category from container
  35. * @param string $key
  36. * @return ItemsContainer
  37. * @throws RegistryException
  38. */
  39. public function get(string $key)
  40. {
  41. if(!$this->has($key)) {
  42. throw new RegistryException('Category not found in registry of shown items');
  43. }
  44. return $this->data[$key];
  45. }
  46. }