-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathServiceList.php
62 lines (57 loc) · 1.32 KB
/
ServiceList.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
<?php
declare(strict_types=1);
namespace Dhii\Services\Factories;
use Dhii\Services\ResolveKeysCapableTrait;
use Dhii\Services\Service;
use Psr\Container\ContainerInterface;
/**
* A service that aggregates other services into a list.
*
* This implementation is configured with a list of service keys. Those keys will be resolved at call-time using the
* container, and the list of resolved values will be returned as the service value.
*
* Example usage:
* ```
* [
* 'foo' => Value(5),
* 'bar' => Value("hello"),
* 'baz' => Value(1.61803),
*
* 'list' => new ServiceList([
* 'foo',
* 'bar',
* 'baz'
* ]),
* ]
*
* $list = $c->get('list'); // [5, "hello", 1.61803]
* ```
*
* The array of service keys may also be associative. The array keys will be preserved in the result.
*
* ```
* [
* 'foo' => Value(5),
* 'bar' => Value("hello"),
*
* 'config' => new ServiceList([
* 'num' => 'foo',
* 'msg' => 'bar'
* ]),
* ]
*
* $list = $c->get('list'); // ['num' => 5, 'msg' => "hello"]
* ```
*
*/
class ServiceList extends Service
{
use ResolveKeysCapableTrait;
/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $c)
{
return $this->resolveDeps($c, $this->dependencies);
}
}