FrontendStorageConfigurationPool.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\Model;
  7. use Magento\Framework\Exception\LocalizedException;
  8. /**
  9. * This pool allows to collect all dynamic data, as settings and provide this data on frontend
  10. * Pool of different storage configuration, which retrieve all dynamic configurations to frontend storage manager
  11. * Each configuration object should have \Magento\Catalog\Model\FrontendStorageConfigurationInterface interface
  12. * Each configuration object provide only dynamic settings. For example, from Stores Configurations
  13. * All configurations will be used in front
  14. */
  15. class FrontendStorageConfigurationPool
  16. {
  17. /**
  18. * @var array
  19. */
  20. private $storageConfigurations;
  21. /**
  22. * StorageConfigurationPool constructor.
  23. * @param array $storageConfigurations
  24. */
  25. public function __construct(array $storageConfigurations = [])
  26. {
  27. $this->storageConfigurations = $storageConfigurations;
  28. }
  29. /**
  30. * Retrieve storage collector (which hold dynamic configurations) by its namespace
  31. *
  32. * @param string $namespace
  33. * @return FrontendStorageConfigurationInterface | bool
  34. * @throws LocalizedException
  35. */
  36. public function get($namespace)
  37. {
  38. if (isset($this->storageConfigurations[$namespace])) {
  39. if (!$this->storageConfigurations[$namespace] instanceof FrontendStorageConfigurationInterface) {
  40. throw new LocalizedException(
  41. __(sprintf("Invalid pool type with namespace: %s", $namespace))
  42. );
  43. }
  44. } else {
  45. return false;
  46. }
  47. return $this->storageConfigurations[$namespace];
  48. }
  49. }