Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/Ecombricks/InventoryConfig/Plugin/App/Config/Source/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/InventoryConfig/Plugin/App/Config/Source/RuntimeConfigSource.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Ecombricks\InventoryConfig\Plugin\App\Config\Source;

/**
 * Runtime configuration source plugin
 */
class RuntimeConfigSource extends \Ecombricks\Framework\Plugin\AbstractPlugin
{
    
    /**
     * Collection factory
     * 
     * @var \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory
     */
    protected $collectionFactory;
    
    /**
     * Scope code resolver
     * 
     * @var \Ecombricks\Inventory\Model\SourceManagement
     */
    protected $scopeCodeResolver;
    
    /**
     * Converter
     * 
     * @var \Magento\Framework\App\Config\Scope\Converter
     */
    protected $converter;
    
    /**
     * Source management
     * 
     * @var \Ecombricks\Inventory\Model\SourceManagement
     */
    protected $sourceManagement;
    
    /**
     * Product metadata
     * 
     * @var \Magento\Framework\App\ProductMetadata 
     */
    protected $productMetadata;
    
    /**
     * Deployment configuration
     * 
     * @var \Magento\Framework\App\DeploymentConfig 
     */
    protected $deploymentConfig;
    
    /**
     * Constructor
     * 
     * @param \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $collectionFactory
     * @param \Magento\Framework\App\Config\ScopeCodeResolver $scopeCodeResolver
     * @param \Magento\Framework\App\Config\Scope\Converter $converter
     * @param \Ecombricks\Inventory\Model\SourceManagement $sourceManagement
     * @param \Magento\Framework\App\ProductMetadata $productMetadata
     * @return void
     */
    public function __construct(
        \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $collectionFactory,
        \Magento\Framework\App\Config\ScopeCodeResolver $scopeCodeResolver,
        \Magento\Framework\App\Config\Scope\Converter $converter,
        \Ecombricks\Inventory\Model\SourceManagement $sourceManagement,
        \Magento\Framework\App\ProductMetadata $productMetadata
    )
    {
        $this->collectionFactory = $collectionFactory;
        $this->scopeCodeResolver = $scopeCodeResolver;
        $this->converter = $converter;
        $this->sourceManagement = $sourceManagement;
        $this->productMetadata = $productMetadata;
        if (version_compare($this->productMetadata->getVersion(), '2.3.6', '>=')) {
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $this->deploymentConfig = $objectManager->get(\Magento\Framework\App\DeploymentConfig::class);
        }
    }
    
    /**
     * Get configuration values
     * 
     * @return \Magento\Framework\App\Config\ValueInterface[]
     */
    protected function getConfigValues()
    {
        try {
            return $this->collectionFactory->create()->getItems();
        } catch (\DomainException $exception) {
            return [];
        } catch (\Magento\Framework\DB\Adapter\TableNotFoundException $exception) {
            return [];
        }
    }
    
    /**
     * Get configuration data
     * 
     * @return array
     */
    protected function getConfigData()
    {
        $config = [];
        foreach ($this->getConfigValues() as $configValue) {
            $scope = $configValue->getScope();
            $scopeId = $configValue->getScopeId();
            $path = $configValue->getPath();
            $value = $configValue->getValue();
            $sourceCode = $configValue->getSourceCode();
            if (empty($scope)) {
                continue;
            }
            if ($scope === \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
                if ($sourceCode) {
                    $config[$scope]['sources'][$sourceCode][$path] = $value;
                } else {
                    $config[$scope][$path] = $value;
                }
            } else {
                $code = $this->scopeCodeResolver->resolve($scope, $scopeId);
                if ($sourceCode) {
                    $config[$scope][$code]['sources'][$sourceCode][$path] = $value;
                } else {
                    $config[$scope][$code][$path] = $value;
                }
            }
        }
        return $config;
    }
    
    /**
     * Load configuration
     * 
     * @return array
     */
    protected function loadConfig()
    {
        $config = $this->getConfigData();
        foreach ($config as $scope => &$item) {
            if ($scope === \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
                $item = $this->converter->convert($item);
                if (!empty($item['sources'])) {
                    foreach ($item['sources'] as $sourceCode => &$sourceItem) {
                        $sourceItem = $this->converter->convert($sourceItem);
                    }
                }
            } else {
                foreach ($item as &$scopeItems) {
                    $scopeItems = $this->converter->convert($scopeItems);
                    if (!empty($scopeItems['sources'])) {
                        foreach ($scopeItems['sources'] as $sourceCode => &$sourceItem) {
                            $sourceItem = $this->converter->convert($sourceItem);
                        }
                    }
                }
            }
        }
        return $config;
    }
    
    /**
     * Get
     * 
     * @param string $path
     * @return array
     */
    protected function get($path)
    {
        if (version_compare($this->productMetadata->getVersion(), '2.3.6', '>=')) {
            $dataObject = new \Magento\Framework\DataObject($this->deploymentConfig->isDbAvailable() ? $this->loadConfig() : []);
        } else {
            $dataObject = new \Magento\Framework\DataObject($this->loadConfig());
        }
        $this->sourceManagement->clearCache();
        return $dataObject->getData($path) !== null ? $dataObject->getData($path) : null;
    }
    
    /**
     * Around get
     *
     * @param \Magento\Config\App\Config\Source\RuntimeConfigSource $subject
     * @param \Closure $proceed
     * @param string $path
     * @return array
     */
    public function aroundGet(
        \Magento\Config\App\Config\Source\RuntimeConfigSource $subject,
        \Closure $proceed,
        $path
    )
    {
        $this->setSubject($subject);
        return $this->get($path);
    }

}

Spamworldpro Mini