Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Config Class Reference
Inheritance diagram for Config:
DataObject

Public Member Functions

 __construct (\Magento\Framework\App\Config\ReinitableConfigInterface $config, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Config\Model\Config\Structure $configStructure, \Magento\Framework\DB\TransactionFactory $transactionFactory, \Magento\Config\Model\Config\Loader $configLoader, \Magento\Framework\App\Config\ValueFactory $configValueFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, SettingChecker $settingChecker=null, array $data=[])
 
 load ()
 
 extendConfig ($path, $full=true, $oldConfig=[])
 
 setDataByPath ($path, $value)
 
 getConfigDataValue ($path, &$inherit=null, $configData=null)
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 _getConfig ($full=true)
 
 _checkSingleStoreMode (\Magento\Config\Model\Config\Structure\Element\Field $fieldConfig, $dataObject)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_configData
 
 $_eventManager
 
 $_configStructure
 
 $_appConfig
 
 $_objectFactory
 
 $_transactionFactory
 
 $_configLoader
 
 $_configValueFactory
 
 $_storeManager
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Backend config model

Used to save configuration

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @SuppressWarnings(PHPMD.CouplingBetweenObjects) @api
Since
100.0.2

Definition at line 22 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Config\ReinitableConfigInterface  $config,
\Magento\Framework\Event\ManagerInterface  $eventManager,
\Magento\Config\Model\Config\Structure  $configStructure,
\Magento\Framework\DB\TransactionFactory  $transactionFactory,
\Magento\Config\Model\Config\Loader  $configLoader,
\Magento\Framework\App\Config\ValueFactory  $configValueFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
SettingChecker  $settingChecker = null,
array  $data = [] 
)
Parameters
\Magento\Framework\App\Config\ReinitableConfigInterface$config
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\Config\Model\Config\Structure$configStructure
\Magento\Framework\DB\TransactionFactory$transactionFactory
\Magento\Config\Model\Config\Loader$configLoader
\Magento\Framework\App\Config\ValueFactory$configValueFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
Config\Reader\Source\Deployed\SettingChecker | null$settingChecker
array$data

Definition at line 101 of file Config.php.

111  {
112  parent::__construct($data);
113  $this->_eventManager = $eventManager;
114  $this->_configStructure = $configStructure;
115  $this->_transactionFactory = $transactionFactory;
116  $this->_appConfig = $config;
117  $this->_configLoader = $configLoader;
118  $this->_configValueFactory = $configValueFactory;
119  $this->_storeManager = $storeManager;
120  $this->settingChecker = $settingChecker ?: ObjectManager::getInstance()->get(SettingChecker::class);
121  }
$config
Definition: fraud_order.php:17
$storeManager

Member Function Documentation

◆ _checkSingleStoreMode()

_checkSingleStoreMode ( \Magento\Config\Model\Config\Structure\Element\Field  $fieldConfig,
  $dataObject 
)
protected

Set correct scope if isSingleStoreMode = true

Parameters
\Magento\Config\Model\Config\Structure\Element\Field$fieldConfig
\Magento\Framework\App\Config\ValueInterface$dataObject
Returns
void

Definition at line 568 of file Config.php.

571  {
572  $isSingleStoreMode = $this->_storeManager->isSingleStoreMode();
573  if (!$isSingleStoreMode) {
574  return;
575  }
576  if (!$fieldConfig->showInDefault()) {
577  $websites = $this->_storeManager->getWebsites();
578  $singleStoreWebsite = array_shift($websites);
579  $dataObject->setScope('websites');
580  $dataObject->setWebsiteCode($singleStoreWebsite->getCode());
581  $dataObject->setScopeCode($singleStoreWebsite->getCode());
582  $dataObject->setScopeId($singleStoreWebsite->getId());
583  }
584  }

◆ _getConfig()

_getConfig (   $full = true)
protected

Return formatted config data for current section

Parameters
bool$fullSimple config structure or not
Returns
array

Definition at line 551 of file Config.php.

552  {
553  return $this->_configLoader->getConfigByPath(
554  $this->getSection(),
555  $this->getScope(),
556  $this->getScopeId(),
557  $full
558  );
559  }

◆ extendConfig()

extendConfig (   $path,
  $full = true,
  $oldConfig = [] 
)

Extend config data with additional config data by specified path

Parameters
string$pathConfig path prefix
bool$fullSimple config structure or not
array$oldConfigConfig data to extend
Returns
array

Definition at line 463 of file Config.php.

464  {
465  $extended = $this->_configLoader->getConfigByPath($path, $this->getScope(), $this->getScopeId(), $full);
466  if (is_array($oldConfig) && !empty($oldConfig)) {
467  return $oldConfig + $extended;
468  }
469  return $extended;
470  }

◆ getConfigDataValue()

getConfigDataValue (   $path,
$inherit = null,
  $configData = null 
)

Get config data value

Parameters
string$path
null | bool&$inherit
null | array$configData
Returns
\Magento\Framework\Simplexml\Element

Definition at line 594 of file Config.php.

595  {
596  $this->load();
597  if ($configData === null) {
599  }
600  if (isset($configData[$path])) {
602  $inherit = false;
603  } else {
604  $data = $this->_appConfig->getValue($path, $this->getScope(), $this->getScopeCode());
605  $inherit = true;
606  }
607 
608  return $data;
609  }

◆ load()

load ( )

Load config data for section

Returns
array

Definition at line 446 of file Config.php.

447  {
448  if ($this->_configData === null) {
449  $this->initScope();
450  $this->_configData = $this->_getConfig(false);
451  }
452  return $this->_configData;
453  }

◆ setDataByPath()

setDataByPath (   $path,
  $value 
)

Add data by path section/group/field

Parameters
string$path
mixed$value
Returns
void
Exceptions

Definition at line 480 of file Config.php.

481  {
482  $path = trim($path);
483  if ($path === '') {
484  throw new \UnexpectedValueException('Path must not be empty');
485  }
486  $pathParts = explode('/', $path);
487  $keyDepth = count($pathParts);
488  if ($keyDepth !== 3) {
489  throw new \UnexpectedValueException(
490  "Allowed depth of configuration is 3 (<section>/<group>/<field>). Your configuration depth is "
491  . $keyDepth . " for path '$path'"
492  );
493  }
494  $data = [
495  'section' => $pathParts[0],
496  'groups' => [
497  $pathParts[1] => [
498  'fields' => [
499  $pathParts[2] => ['value' => $value],
500  ],
501  ],
502  ],
503  ];
504  $this->addData($data);
505  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_appConfig

$_appConfig
protected

Definition at line 50 of file Config.php.

◆ $_configData

$_configData
protected

Definition at line 29 of file Config.php.

◆ $_configLoader

$_configLoader
protected

Definition at line 71 of file Config.php.

◆ $_configStructure

$_configStructure
protected

Definition at line 43 of file Config.php.

◆ $_configValueFactory

$_configValueFactory
protected

Definition at line 78 of file Config.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 36 of file Config.php.

◆ $_objectFactory

$_objectFactory
protected

Definition at line 57 of file Config.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 83 of file Config.php.

◆ $_transactionFactory

$_transactionFactory
protected

Definition at line 64 of file Config.php.


The documentation for this class was generated from the following file: