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

Public Member Functions

 __construct (\Magento\FunctionalTestingFramework\ObjectManager\ConfigInterface $config, \Magento\FunctionalTestingFramework\ObjectManagerInterface $objectManager=null, \Magento\FunctionalTestingFramework\ObjectManager\DefinitionInterface $definitions=null, $globalArguments=[])
 
 setObjectManager (\Magento\FunctionalTestingFramework\ObjectManagerInterface $objectManager)
 
 create ($requestedType, array $arguments=[])
 
 setArguments ($arguments)
 

Protected Member Functions

 resolveArguments ($requestedType, array $parameters, array $arguments=[])
 
 parseArray (&$array)
 

Protected Attributes

 $objectManager
 
 $config
 
 $definitions
 
 $creationStack = []
 
 $globalArguments
 

Detailed Description

Class Developer

Definition at line 11 of file Developer.php.

Constructor & Destructor Documentation

◆ __construct()

Developer constructor.

Parameters
\Magento\FunctionalTestingFramework\ObjectManager\ConfigInterface$config
\Magento\FunctionalTestingFramework\ObjectManagerInterface | null$objectManager
\Magento\FunctionalTestingFramework\ObjectManager\DefinitionInterface | null$definitions
array$globalArguments

Definition at line 55 of file Developer.php.

Member Function Documentation

◆ create()

create (   $requestedType,
array  $arguments = [] 
)

Create instance with call time arguments

Parameters
string$requestedType
array$arguments
Returns
object
Exceptions

Implements FactoryInterface.

Definition at line 177 of file Developer.php.

178  {
179  $type = $this->config->getInstanceType($requestedType);
180  $parameters = $this->definitions->getParameters($type);
181  if ($parameters == null) {
182  return new $type();
183  }
184  if (isset($this->creationStack[$requestedType])) {
185  $lastFound = end($this->creationStack);
186  $this->creationStack = [];
187  throw new \LogicException("Circular dependency: {$requestedType} depends on {$lastFound} and vice versa.");
188  }
189  $this->creationStack[$requestedType] = $requestedType;
190  try {
191  $args = $this->resolveArguments($requestedType, $parameters, $arguments);
192  unset($this->creationStack[$requestedType]);
193  } catch (\Exception $e) {
194  unset($this->creationStack[$requestedType]);
195  throw $e;
196  }
197 
198  $reflection = new \ReflectionClass($type);
199 
200  return $reflection->newInstanceArgs($args);
201  }
$type
Definition: item.phtml:13
$arguments
resolveArguments($requestedType, array $parameters, array $arguments=[])
Definition: Developer.php:91

◆ parseArray()

parseArray ( $array)
protected

Parse array argument

Parameters
array$array
Returns
void

Definition at line 145 of file Developer.php.

146  {
147  foreach ($array as $key => $item) {
148  if (is_array($item)) {
149  if (isset($item['instance'])) {
150  $itemType = $item['instance'];
151  $isShared = (isset($item['shared'])) ? $item['shared'] : $this->config->isShared($itemType);
152  $array[$key] = $isShared
153  ? $this->objectManager->get($itemType)
154  : $this->objectManager->create($itemType);
155  } elseif (isset($item['argument'])) {
156  $array[$key] = isset($this->globalArguments[$item['argument']])
157  ? $this->globalArguments[$item['argument']]
158  : null;
159  } else {
160  $this->parseArray($array[$key]);
161  }
162  }
163  }
164  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ resolveArguments()

resolveArguments (   $requestedType,
array  $parameters,
array  $arguments = [] 
)
protected

Resolve constructor arguments

Parameters
string$requestedType
array$parameters
array$arguments
Returns
array
Exceptions

Definition at line 91 of file Developer.php.

92  {
93  $resolvedArguments = [];
94  $arguments = count($arguments)
95  ? array_replace($this->config->getArguments($requestedType), $arguments)
96  : $this->config->getArguments($requestedType);
97  foreach ($parameters as $parameter) {
98  list($paramName, $paramType, $paramRequired, $paramDefault) = $parameter;
99  $argument = null;
100  if (!empty($arguments) && (isset($arguments[$paramName]) || array_key_exists($paramName, $arguments))) {
101  $argument = $arguments[$paramName];
102  } elseif ($paramRequired) {
103  if ($paramType) {
104  $argument = ['instance' => $paramType];
105  } else {
106  $this->creationStack = [];
107  throw new \BadMethodCallException(
108  'Missing required argument $' . $paramName . ' of ' . $requestedType . '.'
109  );
110  }
111  } else {
112  $argument = $paramDefault;
113  }
114  if ($paramType && $argument !== $paramDefault && !is_object($argument)) {
115  if (!isset($argument['instance']) || !is_array($argument)) {
116  throw new \UnexpectedValueException(
117  'Invalid parameter configuration provided for $' . $paramName . ' argument of ' . $requestedType
118  );
119  }
120  $argumentType = $argument['instance'];
121  $isShared = (isset($argument['shared']) ? $argument['shared'] : $this->config->isShared($argumentType));
122  $argument = $isShared
123  ? $this->objectManager->get($argumentType)
124  : $this->objectManager->create($argumentType);
125  } elseif (is_array($argument)) {
126  if (isset($argument['argument'])) {
127  $argument = isset($this->globalArguments[$argument['argument']])
128  ? $this->globalArguments[$argument['argument']]
129  : $paramDefault;
130  } elseif (!empty($argument)) {
131  $this->parseArray($argument);
132  }
133  }
134  $resolvedArguments[] = $argument;
135  }
136  return $resolvedArguments;
137  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$arguments

◆ setArguments()

setArguments (   $arguments)

Set global arguments

Parameters
array$arguments
Returns
void

Definition at line 209 of file Developer.php.

210  {
211  $this->globalArguments = $arguments;
212  }
$arguments

◆ setObjectManager()

setObjectManager ( \Magento\FunctionalTestingFramework\ObjectManagerInterface  $objectManager)

Set object manager

Parameters
\Magento\FunctionalTestingFramework\ObjectManagerInterface$objectManager
Returns
void

Definition at line 73 of file Developer.php.

Field Documentation

◆ $config

$config
protected

Definition at line 25 of file Developer.php.

◆ $creationStack

$creationStack = []
protected

Definition at line 39 of file Developer.php.

◆ $definitions

$definitions
protected

Definition at line 32 of file Developer.php.

◆ $globalArguments

$globalArguments
protected

Definition at line 46 of file Developer.php.

◆ $objectManager

$objectManager
protected

Definition at line 18 of file Developer.php.


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