Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Compiled.php
Go to the documentation of this file.
1 <?php
7 
8 class Compiled extends AbstractFactory
9 {
15  protected $config;
16 
22  protected $globalArguments;
23 
27  private $sharedInstances;
28 
34  public function __construct(
36  &$sharedInstances = [],
37  $globalArguments = []
38  ) {
39  $this->config = $config;
40  $this->globalArguments = $globalArguments;
41  $this->sharedInstances = &$sharedInstances;
42  }
43 
53  public function create($requestedType, array $arguments = [])
54  {
55  $args = $this->config->getArguments($requestedType);
56  $type = $this->config->getInstanceType($requestedType);
57 
58  if ($args === []) {
59  // Case 1: no arguments required
60  return new $type();
61  } elseif ($args !== null) {
75  foreach ($args as $key => &$argument) {
76  if (isset($arguments[$key])) {
77  $argument = $arguments[$key];
78  } elseif (isset($argument['_i_'])) {
79  $argument = $this->get($argument['_i_']);
80  } elseif (isset($argument['_ins_'])) {
81  $argument = $this->create($argument['_ins_']);
82  } elseif (isset($argument['_v_'])) {
83  $argument = $argument['_v_'];
84  } elseif (isset($argument['_vac_'])) {
85  $argument = $argument['_vac_'];
86  $this->parseArray($argument);
87  } elseif (isset($argument['_vn_'])) {
88  $argument = null;
89  } elseif (isset($argument['_a_'])) {
90  if (isset($this->globalArguments[$argument['_a_']])) {
91  $argument = $this->globalArguments[$argument['_a_']];
92  } else {
93  $argument = $argument['_d_'];
94  }
95  }
96  }
97  $args = array_values($args);
98  } else {
99  // Case 3: arguments retrieved in runtime
100  $parameters = $this->getDefinitions()->getParameters($type) ?: [];
101  $args = $this->resolveArgumentsInRuntime(
102  $type,
103  $parameters,
104  $arguments
105  );
106  }
107 
108  return $this->createObject($type, $args);
109  }
110 
120  protected function parseArray(&$array)
121  {
122  foreach ($array as $key => &$argument) {
123  if ($argument === (array)$argument) {
124  if (isset($argument['_i_'])) {
125  $argument = $this->get($argument['_i_']);
126  } elseif (isset($argument['_ins_'])) {
127  $argument = $this->create($argument['_ins_']);
128  } elseif (isset($argument['_a_'])) {
129  if (isset($this->globalArguments[$argument['_a_']])) {
130  $argument = $this->globalArguments[$argument['_a_']];
131  } else {
132  $argument = $argument['_d_'];
133  }
134  } else {
135  $this->parseArray($argument);
136  }
137  }
138  }
139  }
140 
147  protected function get($type)
148  {
149  if (!isset($this->sharedInstances[$type])) {
150  $this->sharedInstances[$type] = $this->create($type);
151  }
152  return $this->sharedInstances[$type];
153  }
154 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
create($requestedType, array $arguments=[])
Definition: Compiled.php:53
__construct(\Magento\Framework\ObjectManager\ConfigInterface $config, &$sharedInstances=[], $globalArguments=[])
Definition: Compiled.php:34
$type
Definition: item.phtml:13
$arguments
resolveArgumentsInRuntime($requestedType, array $parameters, array $arguments=[])