|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace As3\Bundle\ModlrBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use As3\Bundle\ModlrBundle\DependencyInjection\ServiceLoader\ServiceLoaderInterface; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Loads services for the Modlr bundle |
|
10
|
|
|
* |
|
11
|
|
|
* @author Jacob Bare <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class ServiceLoaderManager |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ContainerBuilder |
|
17
|
|
|
*/ |
|
18
|
|
|
private $container; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ServiceLoaderInterface[] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $loaders = []; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Constructor. |
|
27
|
|
|
* |
|
28
|
|
|
* @param ContainerBuilder $container |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(ContainerBuilder $container) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->container = $container; |
|
33
|
|
|
$this->initLoaders(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Adds a service loader. |
|
38
|
|
|
* |
|
39
|
|
|
* @param ServiceLoaderInterface $loader |
|
40
|
|
|
* @return self |
|
41
|
|
|
*/ |
|
42
|
|
|
public function addLoader(ServiceLoaderInterface $loader) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->loaders[] = $loader; |
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Initializes all service loaders. |
|
50
|
|
|
* |
|
51
|
|
|
* @return self |
|
52
|
|
|
*/ |
|
53
|
|
|
private function initLoaders() |
|
54
|
|
|
{ |
|
55
|
|
|
$namespace = sprintf('%s\\ServiceLoader', __NAMESPACE__); |
|
56
|
|
|
$classes = ['MetadataCache', 'MetadataDrivers', 'MetadataFactory', 'Persisters', 'Rest', 'SearchClients']; |
|
57
|
|
|
|
|
58
|
|
|
foreach ($classes as $class) { |
|
59
|
|
|
$fqcn = sprintf('%s\\%s', $namespace, $class); |
|
60
|
|
|
$this->addLoader(new $fqcn); |
|
61
|
|
|
} |
|
62
|
|
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Loads services from all loaders. |
|
67
|
|
|
* |
|
68
|
|
|
* @param array $config |
|
69
|
|
|
* @return self |
|
70
|
|
|
*/ |
|
71
|
|
|
public function loadServices(array $config) |
|
72
|
|
|
{ |
|
73
|
|
|
foreach ($this->loaders as $loader) { |
|
74
|
|
|
$loader->load($config, $this->container); |
|
75
|
|
|
} |
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|