FrontendStorageConfigurationPool.php 1.72 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Catalog\Model;

use Magento\Framework\Exception\LocalizedException;

/**
 * This pool allows to collect all dynamic data, as settings and provide this data on frontend
 * Pool of different storage configuration, which retrieve all dynamic configurations to frontend storage manager
 * Each configuration object should have \Magento\Catalog\Model\FrontendStorageConfigurationInterface interface
 * Each configuration object provide only dynamic settings. For example, from Stores Configurations
 * All configurations will be used in front
 */
class FrontendStorageConfigurationPool
{
    /**
     * @var array
     */
    private $storageConfigurations;

    /**
     * StorageConfigurationPool constructor.
     * @param array $storageConfigurations
     */
    public function __construct(array $storageConfigurations = [])
    {
        $this->storageConfigurations = $storageConfigurations;
    }

    /**
     * Retrieve storage collector (which hold dynamic configurations) by its namespace
     *
     * @param string $namespace
     * @return FrontendStorageConfigurationInterface | bool
     * @throws LocalizedException
     */
    public function get($namespace)
    {
        if (isset($this->storageConfigurations[$namespace])) {
            if (!$this->storageConfigurations[$namespace] instanceof FrontendStorageConfigurationInterface) {
                throw new LocalizedException(
                    __(sprintf("Invalid pool type with namespace: %s", $namespace))
                );
            }
        } else {
            return false;
        }

        return $this->storageConfigurations[$namespace];
    }
}