1 | <?php |
||
29 | class Objects extends AbstractContainer implements \Caridea\Event\Publisher |
||
30 | { |
||
31 | /** |
||
32 | * @var \Caridea\Container\Provider[] Associative array of string names to providers |
||
33 | */ |
||
34 | protected $providers = []; |
||
35 | /** |
||
36 | * @var \SplObjectStorage A collection of event listeners |
||
37 | */ |
||
38 | protected $listeners; |
||
39 | |||
40 | /** |
||
41 | * Creates a new Object container. |
||
42 | * |
||
43 | * You might find it easier to use the `Builder` instead of this |
||
44 | * constructor. Compare this first example… |
||
45 | * |
||
46 | * ```php |
||
47 | * $props = new \Caridea\Container\Properties([ |
||
48 | * 'mail.host' => 'mail.example.net' |
||
49 | * ]); |
||
50 | * $objects = new \Caridea\Container\Objects([ |
||
51 | * 'mailService' => new Provider('My\Mail\Service', function($c){ |
||
52 | * return new \My\Mail\Service($c['mail.host']); |
||
53 | * }, true), |
||
54 | * 'userService' => new Provider('My\User\Service', function($c){ |
||
55 | * return new \My\User\Service($c['mailService']); |
||
56 | * }, false) |
||
57 | * ], $props); |
||
58 | * ``` |
||
59 | * |
||
60 | * …to this one: |
||
61 | * |
||
62 | * ```php |
||
63 | * $props = new \Caridea\Container\Properties([ |
||
64 | * 'mail.host' => 'mail.example.net' |
||
65 | * ]); |
||
66 | * $objects = \Caridea\Container\Objects::builder() |
||
67 | * ->lazy('mailService', 'My\Mail\Service', function($c){ |
||
68 | * return new \My\Mail\Service($c['mail.host']); |
||
69 | * }) |
||
70 | * ->proto('userService', 'My\User\Service', function($c){ |
||
71 | * return new \My\User\Service($c['mailService']); |
||
72 | * }) |
||
73 | * ->build($props); |
||
74 | * ``` |
||
75 | * |
||
76 | * @param \Caridea\Container\Provider[] $providers with names as keys |
||
77 | * @param \Caridea\Container\Container $parent An optional parent container |
||
78 | */ |
||
79 | 4 | public function __construct(array $providers, Container $parent = null) |
|
91 | |||
92 | /** |
||
93 | * Creates a new Builder. |
||
94 | * |
||
95 | * @return \Caridea\Container\Builder A new `Objects` builder |
||
96 | */ |
||
97 | 1 | public static function builder(): Builder |
|
101 | |||
102 | /** |
||
103 | * Retrieves the value |
||
104 | * |
||
105 | * @param string $name The value name |
||
106 | */ |
||
107 | 5 | protected function doGet(string $name) |
|
128 | |||
129 | /** |
||
130 | * Queues an event to be sent to Listeners. |
||
131 | * |
||
132 | * @param \Caridea\Event\Event $event The event to publish |
||
133 | */ |
||
134 | 2 | public function publish(\Caridea\Event\Event $event) |
|
140 | } |
||
141 |