-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathDeveloper.php
68 lines (64 loc) · 2.21 KB
/
Developer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\ObjectManager\Factory\Dynamic;
class Developer extends \Magento\Framework\ObjectManager\Factory\AbstractFactory
{
/**
* Resolve constructor arguments
*
* @param string $requestedType
* @param array $parameters
* @param array $arguments
*
* @return array
*
* @throws \UnexpectedValueException
* @throws \BadMethodCallException
*/
protected function _resolveArguments($requestedType, array $parameters, array $arguments = [])
{
// Get default arguments from config, merge with supplied arguments
$defaultArguments = $this->config->getArguments($requestedType);
if (is_array($defaultArguments)) {
if (count($arguments)) {
$arguments = array_replace($defaultArguments, $arguments);
} else {
$arguments = $defaultArguments;
}
}
return $this->resolveArgumentsInRuntime($requestedType, $parameters, $arguments);
}
/**
* Create instance with call time arguments
*
* @param string $requestedType
* @param array $arguments
* @return object
* @throws \Exception
*/
public function create($requestedType, array $arguments = [])
{
$type = $this->config->getInstanceType($requestedType);
$parameters = $this->definitions->getParameters($type);
if ($parameters == null) {
return new $type();
}
if (isset($this->creationStack[$requestedType])) {
$lastFound = end($this->creationStack);
$this->creationStack = [];
throw new \LogicException("Circular dependency: {$requestedType} depends on {$lastFound} and vice versa.");
}
$this->creationStack[$requestedType] = $requestedType;
try {
$args = $this->_resolveArguments($requestedType, $parameters, $arguments);
unset($this->creationStack[$requestedType]);
} catch (\Exception $e) {
unset($this->creationStack[$requestedType]);
throw $e;
}
return $this->createObject($type, $args);
}
}