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

Public Member Functions

 __construct (ComponentDefinition $componentConfigProvider, DomMergerInterface $domMerger, ReaderFactory $readerFactory, ArrayObjectFactory $arrayObjectFactory, AggregatedFileCollectorFactory $aggregatedFileCollectorFactory, CacheInterface $cache, InterpreterInterface $argumentInterpreter, SerializerInterface $serializer=null)
 
 getData ($name)
 
 prepareData ($name)
 
 createRawComponentData ($component, $evaluated=true)
 
 getReader ($name)
 
- Public Member Functions inherited from ManagerInterface
 createRawComponentData ($component)
 

Data Fields

const CACHE_ID = 'ui_component_configuration_data'
 
- Data Fields inherited from ManagerInterface
const SEARCH_PATTERN = '%s.xml'
 
const ANONYMOUS_TEMPLATE = 'anonymous_%s_component_%d'
 
const COMPONENT_ARGUMENTS_KEY = 'arguments'
 
const COMPONENT_ATTRIBUTES_KEY = 'attributes'
 
const CHILDREN_KEY = 'children'
 

Protected Member Functions

 hasData ($name)
 
 evaluateComponentArguments ($components)
 
 prepare ($name)
 
 createDataForComponent ($name, array $componentsPool)
 
 addComponentIntoPool ($instanceName, array $configuration)
 
 mergeArguments (array $componentData, array $rootComponentData)
 
 mergeAttributes (array $componentData, array $rootComponentData)
 
 createName (array $componentData, $key, $componentName)
 

Protected Attributes

 $componentConfigProvider
 
 $argumentInterpreter
 
 $domMerger
 
 $readerFactory
 
 $componentsData
 
 $componentsPool
 
 $arrayObjectFactory
 
 $aggregatedFileCollectorFactory
 
 $cache
 
 $uiReader
 

Detailed Description

Class Manager

Deprecated:
101.0.0 @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 29 of file Manager.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ComponentDefinition  $componentConfigProvider,
DomMergerInterface  $domMerger,
ReaderFactory  $readerFactory,
ArrayObjectFactory  $arrayObjectFactory,
AggregatedFileCollectorFactory  $aggregatedFileCollectorFactory,
CacheInterface  $cache,
InterpreterInterface  $argumentInterpreter,
SerializerInterface  $serializer = null 
)
Parameters
ComponentDefinition$componentConfigProvider
DomMergerInterface$domMerger
ReaderFactory$readerFactory
ArrayObjectFactory$arrayObjectFactory
AggregatedFileCollectorFactory$aggregatedFileCollectorFactory
CacheInterface$cache
InterpreterInterface$argumentInterpreter
SerializerInterface | null$serializer

Definition at line 115 of file Manager.php.

124  {
125  $this->componentConfigProvider = $componentConfigProvider;
126  $this->domMerger = $domMerger;
127  $this->readerFactory = $readerFactory;
128  $this->arrayObjectFactory = $arrayObjectFactory;
129  $this->componentsData = $this->arrayObjectFactory->create();
130  $this->aggregatedFileCollectorFactory = $aggregatedFileCollectorFactory;
131  $this->cache = $cache;
132  $this->argumentInterpreter = $argumentInterpreter;
133  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
134  }

Member Function Documentation

◆ addComponentIntoPool()

addComponentIntoPool (   $instanceName,
array  $configuration 
)
protected

Add a component into pool

Parameters
string$instanceName
array$configuration
Returns
void

Definition at line 335 of file Manager.php.

336  {
337  $this->componentsPool->offsetSet($instanceName, $configuration);
338  }
$configuration
Definition: index.php:33

◆ createDataForComponent()

createDataForComponent (   $name,
array  $componentsPool 
)
protected

Create data for component instance

Parameters
string$name
array$componentsPool
Returns
array

Definition at line 295 of file Manager.php.

296  {
297  $createdComponents = [];
298  $rootComponent = $this->createRawComponentData($name, false);
299  foreach ($componentsPool as $key => $component) {
300  $resultConfiguration = [ManagerInterface::CHILDREN_KEY => []];
301  $instanceName = $this->createName($component, $key, $name);
302  $resultConfiguration[ManagerInterface::COMPONENT_ARGUMENTS_KEY] = $this->mergeArguments(
303  $component,
304  $rootComponent
305  );
306  unset($component[Converter::DATA_ARGUMENTS_KEY]);
307  $resultConfiguration[ManagerInterface::COMPONENT_ATTRIBUTES_KEY] = $this->mergeAttributes(
308  $component,
309  $rootComponent
310  );
311  unset($component[Converter::DATA_ATTRIBUTES_KEY]);
312 
313  // Create inner components
314  foreach ($component as $subComponentName => $subComponent) {
315  if (is_array($subComponent)) {
316  $resultConfiguration[ManagerInterface::CHILDREN_KEY] = array_merge(
317  $resultConfiguration[ManagerInterface::CHILDREN_KEY],
318  $this->createDataForComponent($subComponentName, $subComponent)
319  );
320  }
321  }
322  $createdComponents[$instanceName] = $resultConfiguration;
323  }
324 
325  return $createdComponents;
326  }
createName(array $componentData, $key, $componentName)
Definition: Manager.php:387
createDataForComponent($name, array $componentsPool)
Definition: Manager.php:295
mergeAttributes(array $componentData, array $rootComponentData)
Definition: Manager.php:366
mergeArguments(array $componentData, array $rootComponentData)
Definition: Manager.php:347
createRawComponentData($component, $evaluated=true)
Definition: Manager.php:224
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ createName()

createName ( array  $componentData,
  $key,
  $componentName 
)
protected

Create name component instance

Parameters
array$componentData
string | int$key
string$componentName
Returns
string

Definition at line 387 of file Manager.php.

◆ createRawComponentData()

createRawComponentData (   $component,
  $evaluated = true 
)

To create the raw data components

Parameters
string$component
bool$evaluated
Returns
array

Definition at line 224 of file Manager.php.

225  {
226  $componentData = $this->componentConfigProvider->getComponentData($component);
227  $componentData[Converter::DATA_ATTRIBUTES_KEY] = isset($componentData[Converter::DATA_ATTRIBUTES_KEY])
228  ? $componentData[Converter::DATA_ATTRIBUTES_KEY]
229  : [];
230  $componentData[Converter::DATA_ARGUMENTS_KEY] = isset($componentData[Converter::DATA_ARGUMENTS_KEY])
231  ? $componentData[Converter::DATA_ARGUMENTS_KEY]
232  : [];
233  if ($evaluated) {
234  foreach ($componentData[Converter::DATA_ARGUMENTS_KEY] as $argumentName => $argument) {
235  $componentData[Converter::DATA_ARGUMENTS_KEY][$argumentName]
236  = $this->argumentInterpreter->evaluate($argument);
237  }
238  }
239 
240  return [
243  ];
244  }

◆ evaluateComponentArguments()

evaluateComponentArguments (   $components)
protected

Evaluated components data

Parameters
array$components
Returns
array

Definition at line 202 of file Manager.php.

203  {
204  foreach ($components as &$component) {
205  foreach ($component[ManagerInterface::COMPONENT_ARGUMENTS_KEY] as $argumentName => $argument) {
206  $component[ManagerInterface::COMPONENT_ARGUMENTS_KEY][$argumentName]
207  = $this->argumentInterpreter->evaluate($argument);
208  }
211  );
212  }
213 
214  return $components;
215  }
evaluateComponentArguments($components)
Definition: Manager.php:202

◆ getData()

getData (   $name)

Get component data

Parameters
string$name
Returns
array

Implements ManagerInterface.

Definition at line 142 of file Manager.php.

143  {
144  return (array) $this->componentsData->offsetGet($name);
145  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getReader()

getReader (   $name)

Get UIReader and collect base files configuration

Parameters
string$name
Returns
UiReaderInterface

Implements ManagerInterface.

Definition at line 252 of file Manager.php.

253  {
254  if (!isset($this->uiReader[$name])) {
255  $this->domMerger->unsetDom();
256  $this->uiReader[$name] = $this->readerFactory->create(
257  [
258  'fileCollector' => $this->aggregatedFileCollectorFactory->create(
259  ['searchPattern' => sprintf(ManagerInterface::SEARCH_PATTERN, $name)]
260  ),
261  'domMerger' => $this->domMerger
262  ]
263  );
264  }
265 
266  return $this->uiReader[$name];
267  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ hasData()

hasData (   $name)
protected

Has component data

Parameters
string$name
Returns
bool

Definition at line 153 of file Manager.php.

154  {
155  return $this->componentsData->offsetExists($name);
156  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ mergeArguments()

mergeArguments ( array  $componentData,
array  $rootComponentData 
)
protected

Merge component arguments

Parameters
array$componentData
array$rootComponentData
Returns
array

Definition at line 347 of file Manager.php.

348  {
349  $baseArguments = isset($rootComponentData[ManagerInterface::COMPONENT_ARGUMENTS_KEY])
350  ? $rootComponentData[ManagerInterface::COMPONENT_ARGUMENTS_KEY]
351  : [];
352  $componentArguments = isset($componentData[Converter::DATA_ARGUMENTS_KEY])
353  ? $componentData[Converter::DATA_ARGUMENTS_KEY]
354  : [];
355 
356  return array_replace_recursive($baseArguments, $componentArguments);
357  }

◆ mergeAttributes()

mergeAttributes ( array  $componentData,
array  $rootComponentData 
)
protected

Merge component attributes

Parameters
array$componentData
array$rootComponentData
Returns
array

Definition at line 366 of file Manager.php.

367  {
368  $baseAttributes = isset($rootComponentData[ManagerInterface::COMPONENT_ATTRIBUTES_KEY])
369  ? $rootComponentData[ManagerInterface::COMPONENT_ATTRIBUTES_KEY]
370  : [];
371  $componentAttributes = isset($componentData[Converter::DATA_ATTRIBUTES_KEY])
372  ? $componentData[Converter::DATA_ATTRIBUTES_KEY]
373  : [];
374  unset($componentAttributes['noNamespaceSchemaLocation']);
375 
376  return array_replace_recursive($baseAttributes, $componentAttributes);
377  }

◆ prepare()

prepare (   $name)
protected

Initialize the new component data

Parameters
string$name
Returns
void

Definition at line 275 of file Manager.php.

276  {
277  $componentData = $this->getReader($name)->read();
278  $componentsPool = reset($componentData);
281  ['name' => $name],
283  );
284  $components = $this->createDataForComponent(key($componentData), [$componentsPool]);
285  $this->addComponentIntoPool($name, reset($components));
286  }
createDataForComponent($name, array $componentsPool)
Definition: Manager.php:295
addComponentIntoPool($instanceName, array $configuration)
Definition: Manager.php:335
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ prepareData()

prepareData (   $name)

Prepare the initialization data of UI components

Parameters
string$name
Returns
ManagerInterface
Exceptions

Implements ManagerInterface.

Definition at line 165 of file Manager.php.

166  {
167  if ($name === null || $this->hasData($name)) {
168  throw new LocalizedException(
169  new \Magento\Framework\Phrase(
170  'The "%1" UI component element name is invalid. Verify the name and try again.',
171  [$name]
172  )
173  );
174  }
175  $this->componentsPool = $this->arrayObjectFactory->create();
176 
177  $cacheID = static::CACHE_ID . '_' . $name;
178  $cachedPool = $this->cache->load($cacheID);
179  if ($cachedPool === false) {
180  $this->prepare($name);
181  $this->cache->save(
182  $this->serializer->serialize($this->componentsPool->getArrayCopy()),
183  $cacheID
184  );
185  } else {
186  $this->componentsPool->exchangeArray(
187  $this->serializer->unserialize($cachedPool)
188  );
189  }
190  $this->componentsData->offsetSet($name, $this->componentsPool);
191  $this->componentsData->offsetSet($name, $this->evaluateComponentArguments($this->getData($name)));
192 
193  return $this;
194  }
evaluateComponentArguments($components)
Definition: Manager.php:202
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $aggregatedFileCollectorFactory

$aggregatedFileCollectorFactory
protected

Definition at line 88 of file Manager.php.

◆ $argumentInterpreter

$argumentInterpreter
protected

Definition at line 48 of file Manager.php.

◆ $arrayObjectFactory

$arrayObjectFactory
protected

Definition at line 83 of file Manager.php.

◆ $cache

$cache
protected

Definition at line 93 of file Manager.php.

◆ $componentConfigProvider

$componentConfigProvider
protected

Definition at line 41 of file Manager.php.

◆ $componentsData

$componentsData
protected

Definition at line 69 of file Manager.php.

◆ $componentsPool

$componentsPool
protected

Definition at line 76 of file Manager.php.

◆ $domMerger

$domMerger
protected

Definition at line 55 of file Manager.php.

◆ $readerFactory

$readerFactory
protected

Definition at line 62 of file Manager.php.

◆ $uiReader

$uiReader
protected

Definition at line 98 of file Manager.php.

◆ CACHE_ID

const CACHE_ID = 'ui_component_configuration_data'

ID in the storage cache

Definition at line 34 of file Manager.php.


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