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

Public Member Functions

 __construct (FileResolverInterface $fileResolver, ConverterInterface $converter, SchemaLocatorInterface $schemaLocator, ValidationStateInterface $validationState, $fileName, $idAttributes=[], $domDocumentClass=\Magento\Framework\Config\Dom::class, $defaultScope='global', $xpath=[])
 
 getVars ($module)
 
 getVarValue ($module, $var)
 
 getMediaEntities ($module, $mediaType)
 
 getMediaAttributes ($module, $mediaType, $mediaId)
 
 getExcludedFiles ()
 
 getExcludedDir ()
 
 read ($scope=null)
 
- Public Member Functions inherited from Filesystem
 __construct (\Magento\Framework\Config\FileResolverInterface $fileResolver, \Magento\Framework\Config\ConverterInterface $converter, \Magento\Framework\Config\SchemaLocatorInterface $schemaLocator, \Magento\Framework\Config\ValidationStateInterface $validationState, $fileName, $idAttributes=[], $domDocumentClass=\Magento\Framework\Config\Dom::class, $defaultScope='global')
 
 read ($scope=null)
 

Protected Member Functions

 getIdAttributes ()
 
 getItems ()
 
 initData ()
 
- Protected Member Functions inherited from Filesystem
 _createConfigMerger ($mergerClass, $initialContents)
 

Protected Attributes

 $xpath
 
 $data
 
- Protected Attributes inherited from Filesystem
 $_fileResolver
 
 $_converter
 
 $_fileName
 
 $_schema
 
 $_perFileSchema
 
 $_idAttributes = []
 
 $_domDocumentClass
 
 $validationState
 
 $_defaultScope
 
 $_schemaFile
 

Detailed Description

View configuration files handler

@api

Since
100.0.2

Definition at line 14 of file View.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( FileResolverInterface  $fileResolver,
ConverterInterface  $converter,
SchemaLocatorInterface  $schemaLocator,
ValidationStateInterface  $validationState,
  $fileName,
  $idAttributes = [],
  $domDocumentClass = \Magento\Framework\Config\Dom::class,
  $defaultScope = 'global',
  $xpath = [] 
)
Parameters
FileResolverInterface$fileResolver
ConverterInterface$converter
SchemaLocatorInterface$schemaLocator
ValidationStateInterface$validationState
string$fileName
array$idAttributes
string$domDocumentClass
string$defaultScope
array$xpath

Definition at line 39 of file View.php.

49  {
50  $this->xpath = $xpath;
51  $idAttributes = $this->getIdAttributes();
52  parent::__construct(
53  $fileResolver,
54  $converter,
55  $schemaLocator,
57  $fileName,
58  $idAttributes,
59  $domDocumentClass,
60  $defaultScope
61  );
62  }
$fileName
Definition: translate.phtml:15

Member Function Documentation

◆ getExcludedDir()

getExcludedDir ( )

Get excluded directory list

Returns
array

Definition at line 173 of file View.php.

174  {
175  $items = $this->getItems();
176  return $items['directory'] ?? [];
177  }
$items

◆ getExcludedFiles()

getExcludedFiles ( )

Get excluded file list

Returns
array

Definition at line 162 of file View.php.

163  {
164  $items = $this->getItems();
165  return $items['file'] ?? [];
166  }
$items

◆ getIdAttributes()

getIdAttributes ( )
protected

Variables are identified by module and name

Returns
array

Definition at line 136 of file View.php.

137  {
138  $idAttributes = [
139  '/view/vars' => 'module',
140  '/view/vars/(var/)*var' => 'name',
141  '/view/exclude/item' => ['type', 'item'],
142  ];
143  foreach ($this->xpath as $attribute) {
144  if (is_array($attribute)) {
145  foreach ($attribute as $key => $id) {
146  if (count($id) > 1) {
147  $idAttributes[$key] = array_values($id);
148  } else {
149  $idAttributes[$key] = array_shift($id);
150  }
151  }
152  }
153  }
154  return $idAttributes;
155  }
$id
Definition: fieldset.phtml:14

◆ getItems()

getItems ( )
protected

Get a list of excludes

Returns
array

Definition at line 184 of file View.php.

185  {
186  $this->initData();
187  return $this->data['exclude'] ?? [];
188  }

◆ getMediaAttributes()

getMediaAttributes (   $module,
  $mediaType,
  $mediaId 
)

Retrieve array of media attributes

Parameters
string$module
string$mediaType
string$mediaId
Returns
array

Definition at line 125 of file View.php.

126  {
127  $this->initData();
128  return $this->data['media'][$module][$mediaType][$mediaId] ?? [];
129  }

◆ getMediaEntities()

getMediaEntities (   $module,
  $mediaType 
)

Retrieve a list media attributes in scope of specified module

Parameters
string$module
string$mediaType
Returns
array

Definition at line 111 of file View.php.

112  {
113  $this->initData();
114  return $this->data['media'][$module][$mediaType] ?? [];
115  }

◆ getVars()

getVars (   $module)

Get a list of variables in scope of specified module

Returns array(<var_name> => <var_value>)

Parameters
string$module
Returns
array

Definition at line 72 of file View.php.

73  {
74  $this->initData();
75  return $this->data['vars'][$module] ?? [];
76  }

◆ getVarValue()

getVarValue (   $module,
  $var 
)

Get value of a configuration option variable

Parameters
string$module
string$var
Returns
string|false|array

Definition at line 85 of file View.php.

86  {
87  $this->initData();
88  if (!isset($this->data['vars'][$module])) {
89  return false;
90  }
91 
92  $value = $this->data['vars'][$module];
93  foreach (explode('/', $var) as $node) {
94  if (is_array($value) && isset($value[$node])) {
95  $value = $value[$node];
96  } else {
97  return false;
98  }
99  }
100 
101  return $value;
102  }
$value
Definition: gender.phtml:16

◆ initData()

initData ( )
protected

Initialize data array

Returns
void

Definition at line 195 of file View.php.

196  {
197  if ($this->data === null) {
198  $this->data = $this->read();
199  }
200  }

◆ read()

read (   $scope = null)

{Read configuration scope

Parameters
string | null$scope
Returns
array
}

Since
100.1.0

Implements ReaderInterface.

Definition at line 206 of file View.php.

207  {
208  $scope = $scope ?: $this->_defaultScope;
209  $result = [];
210 
211  $parents = (array)$this->_fileResolver->getParents($this->_fileName, $scope);
212  // Sort parents desc
213  krsort($parents);
214 
215  foreach ($parents as $parent) {
216  $result = array_replace_recursive($result, $this->_readFiles([$parent]));
217  }
218 
219  return array_replace_recursive($result, parent::read($scope));
220  }

Field Documentation

◆ $data

$data
protected

Definition at line 26 of file View.php.

◆ $xpath

$xpath
protected

Definition at line 19 of file View.php.


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