![]() 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/Framework/App/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See COPYING.txt for license details. */ namespace Ecombricks\InventoryConfig\Plugin\Framework\App; /** * Config plugin */ class Config extends \Ecombricks\Framework\Plugin\AbstractPlugin { /** * Scope code resolver * * @var \Magento\Framework\App\Config\ScopeCodeResolver */ protected $scopeCodeResolver; /** * Constructor * * @param \Magento\Framework\App\Config\ScopeCodeResolver $scopeCodeResolver * @return void */ public function __construct( \Magento\Framework\App\Config\ScopeCodeResolver $scopeCodeResolver ) { $this->scopeCodeResolver = $scopeCodeResolver; } /** * Get scope path * * @param string $scope * @param string|null $scopeCode * @return string */ protected function getScopePath($scope, $scopeCode) { if ($scope === 'store') { $scope = 'stores'; } elseif ($scope === 'website') { $scope = 'websites'; } $scopePath = $scope; if ($scope !== 'default') { if (is_numeric($scopeCode) || $scopeCode === null) { $scopeCode = $this->scopeCodeResolver->resolve($scope, $scopeCode); } else if ($scopeCode instanceof \Magento\Framework\App\ScopeInterface) { $scopeCode = $scopeCode->getCode(); } if ($scopeCode) { $scopePath .= '/'.$scopeCode; } } return $scopePath; } /** * Get source config path * * @param string $scopePath * @param string|null $path * @return string */ protected function getSourceConfigPath($scopePath, $path) { $sourceCode = $this->getSubject()->getSourceCode(); return $scopePath.'/sources/'.$sourceCode.(($path) ? '/'.$path : ''); } /** * Get config path * * @param string $scopePath * @param string|null $path * @return string */ protected function getConfigPath($scopePath, $path) { return $scopePath.(($path) ? '/'.$path : ''); } /** * Get source value * * @param string $scopePath * @param string|null $path * @return mixed */ protected function getSourceValue($scopePath, $path) { $subject = $this->getSubject(); $sourceCode = $subject->getSourceCode(); if (empty($sourceCode)) { return null; } return $subject->get('system', $this->getSourceConfigPath($scopePath, $path)); } /** * Get value * * @param string|null $path * @param string $scope * @param string|null $scopeCode * @return mixed */ protected function getValue($path, $scope, $scopeCode) { $subject = $this->getSubject(); $scopePath = $this->getScopePath($scope, $scopeCode); $sourceValue = $this->getSourceValue($scopePath, $path); if (($sourceValue !== null) && !is_array($sourceValue)) { return $sourceValue; } $value = $subject->get('system', $this->getConfigPath($scopePath, $path)); if (($sourceValue !== null) && is_array($sourceValue)) { if (is_array($value)) { $value = array_replace_recursive($value, $sourceValue); } else { $value = $sourceValue; } } return $value; } /** * Around get value * * @param \Magento\Framework\App\Config $subject * @param \Closure $proceed * @param string $path * @param string $scope * @param null|string $scopeCode * @return mixed */ public function aroundGetValue( \Magento\Framework\App\Config $subject, \Closure $proceed, $path = null, $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null ) { $this->setSubject($subject); return $this->getValue($path, $scope, $scopeCode); } }