-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArrayExtension.php
53 lines (48 loc) · 1.31 KB
/
ArrayExtension.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
<?php
declare(strict_types=1);
namespace Dhii\Services\Extensions;
use Dhii\Services\ResolveKeysCapableTrait;
use Dhii\Services\Service;
use Psr\Container\ContainerInterface;
/**
* An extension implementation that extends an array service.
*
* This implementation is configured with a list of service keys. These service keys will be resolved at call-time using
* the container, and the resolved list of service values will be merged with the original service's value.
*
* Note: This implementation uses {@link array_merge()} to extend the original array service. This means that positional
* entries are not overwritten, but associative entries are.
*
* Example usage:
* ```
* // Factories
* [
* 'menu_links' => new Value([]),
*
* 'home_link' => new Value('Home'),
* 'blog_link' => new Value('Blog'),
* 'about_link' => new Value('About Us'),
* ]
*
* // Extensions
* [
* 'menu_links' => new ArrayExtension([
* 'home_link',
* 'blog_link',
* 'about_link',
* ]),
* ]
* ```
*
*/
class ArrayExtension extends Service
{
use ResolveKeysCapableTrait;
/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $c, array $prev = [])
{
return array_merge($prev, $this->resolveDeps($c, $this->dependencies));
}
}