1 | <?php |
||
13 | final class NewInstance |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $class; |
||
19 | |||
20 | /** |
||
21 | * @var SetterMethods |
||
22 | */ |
||
23 | private $setterMethods; |
||
24 | |||
25 | /** |
||
26 | * @var Arguments |
||
27 | */ |
||
28 | private $arguments; |
||
29 | |||
30 | /** |
||
31 | * @var AspectBind |
||
32 | */ |
||
33 | private $bind; |
||
34 | |||
35 | 31 | public function __construct( |
|
48 | |||
49 | /** |
||
50 | * @param Container $container |
||
51 | * |
||
52 | * @return object |
||
53 | */ |
||
54 | 25 | public function __invoke(Container $container) |
|
55 | { |
||
56 | // constructor injection |
||
57 | 25 | $instance = $this->arguments ? (new \ReflectionClass($this->class))->newInstanceArgs($this->arguments->inject($container)) : new $this->class; |
|
58 | |||
59 | // setter injection |
||
60 | 25 | ($this->setterMethods)($instance, $container); |
|
61 | |||
62 | // bind dependency injected interceptors |
||
63 | 25 | if ($this->bind instanceof AspectBind) { |
|
64 | $instance->bindings = $this->bind->inject($container); |
||
65 | } |
||
66 | |||
67 | 25 | return $instance; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function __toString() |
|
77 | |||
78 | /** |
||
79 | * @param string $class |
||
80 | * @param AopBind $bind |
||
81 | */ |
||
82 | 1 | public function weaveAspects($class, AopBind $bind) |
|
87 | } |
||
88 |