InitialConfigSource.php 1.85 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Store\App\Config\Source;

use Magento\Framework\App\Config\ConfigSourceInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\DeploymentConfig\Reader;

/**
 * Config source. Retrieve all configuration data from files for specified config type
 */
class InitialConfigSource implements ConfigSourceInterface
{
    /**
     * The file reader
     *
     * @var Reader
     */
    private $reader;

    /**
     * The deployment config reader
     *
     * @var DeploymentConfig
     */
    private $deploymentConfig;

    /**
     * The config type
     *
     * @var string
     */
    private $configType;

    /**
     * @param Reader $reader The file reader
     * @param DeploymentConfig $deploymentConfig The deployment config reader
     * @param string $configType The config type
     */
    public function __construct(
        Reader $reader,
        DeploymentConfig $deploymentConfig,
        $configType
    ) {
        $this->reader = $reader;
        $this->deploymentConfig = $deploymentConfig;
        $this->configType = $configType;
    }

    /**
     * Return whole config data from config file for specified config type.
     * Ignore $path argument due to config source must return all config data
     *
     * @param string $path
     * @return array
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function get($path = '')
    {
        /**
         * Magento store configuration should not be read from file source if database is available
         *
         * @see \Magento\Store\Model\Config\Importer To import store configs
         */
        if ($this->deploymentConfig->isAvailable()) {
            return [];
        }

        return $this->reader->load()[$this->configType] ?? [];
    }
}