123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Config\Model\Config\Reader\Source\Deployed;
- use Magento\Config\Model\Config\Reader;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Framework\App\DeploymentConfig;
- use Magento\Config\Model\Placeholder\PlaceholderInterface;
- use Magento\Config\Model\Placeholder\PlaceholderFactory;
- use Magento\Framework\App\Config\ScopeCodeResolver;
- /**
- * Class for checking settings that defined in config file
- * @api
- * @since 100.1.2
- */
- class SettingChecker
- {
- /**
- * @var DeploymentConfig
- */
- private $config;
- /**
- * @var PlaceholderInterface
- */
- private $placeholder;
- /**
- * @var ScopeCodeResolver
- */
- private $scopeCodeResolver;
- /**
- * @param DeploymentConfig $config
- * @param PlaceholderFactory $placeholderFactory
- * @param ScopeCodeResolver $scopeCodeResolver
- */
- public function __construct(
- DeploymentConfig $config,
- PlaceholderFactory $placeholderFactory,
- ScopeCodeResolver $scopeCodeResolver
- ) {
- $this->config = $config;
- $this->scopeCodeResolver = $scopeCodeResolver;
- $this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
- }
- /**
- * Check that setting defined in deployed configuration
- *
- * @param string $path
- * @param string $scope
- * @param string|null $scopeCode
- * @return boolean
- * @since 100.1.2
- */
- public function isReadOnly($path, $scope, $scopeCode = null)
- {
- $config = $this->getEnvValue(
- $this->placeholder->generate($path, $scope, $scopeCode)
- );
- if (null === $config) {
- $config = $this->config->get($this->resolvePath($scope, $scopeCode) . "/" . $path);
- }
- return $config !== null;
- }
- /**
- * Check that there is value for generated placeholder
- *
- * Placeholder is generated from values of $path, $scope and $scopeCode
- *
- * @param string $path
- * @param string $scope
- * @param string $scopeCode
- * @param string|null $scopeCode
- * @return string|null
- * @since 100.1.2
- */
- public function getPlaceholderValue($path, $scope, $scopeCode = null)
- {
- return $this->getEnvValue($this->placeholder->generate($path, $scope, $scopeCode));
- }
- /**
- * Retrieve value of environment variable by placeholder
- *
- * @param string $placeholder
- * @return string|null
- * @since 100.1.2
- */
- public function getEnvValue($placeholder)
- {
- if ($this->placeholder->isApplicable($placeholder) && isset($_ENV[$placeholder])) {
- return $_ENV[$placeholder];
- }
- return null;
- }
- /**
- * Resolve path by scope and scope code
- *
- * @param string $scope
- * @param string $scopeCode
- * @return string
- */
- private function resolvePath($scope, $scopeCode)
- {
- $scopePath = 'system/' . $scope;
- if ($scope != ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
- $scopePath .= '/' . $this->scopeCodeResolver->resolve($scope, $scopeCode);
- }
- return $scopePath;
- }
- }
|