Conditions | 5 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
50 | public function set($keyword, $factory) |
||
51 | { |
||
52 | if (!(is_string($factory) || $factory instanceof \Closure)) { |
||
53 | throw new \InvalidArgumentException( |
||
54 | sprintf('Expected a string or Closure, got %s', gettype($keyword)) |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | $this->rules[$keyword] = function ($container) use ($factory) { |
||
59 | static $object; |
||
60 | |||
61 | if (is_null($object)) { |
||
62 | $object = is_string($factory) ? new $factory() : $factory($container); |
||
63 | } |
||
64 | |||
65 | return $object; |
||
66 | }; |
||
67 | } |
||
68 | } |
||
69 |