1 | <?php |
||
17 | class ConfigManager implements ManagerInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var IndexConfig[] |
||
21 | */ |
||
22 | private $indexes = array(); |
||
23 | |||
24 | /** |
||
25 | * @param Source\SourceInterface[] $sources |
||
26 | */ |
||
27 | 6 | public function __construct(array $sources) |
|
28 | { |
||
29 | 6 | foreach ($sources as $source) { |
|
30 | 6 | $this->indexes = array_merge($source->getConfiguration(), $this->indexes); |
|
31 | 6 | } |
|
32 | 6 | } |
|
33 | |||
34 | 6 | public function getIndexConfiguration($indexName) |
|
35 | { |
||
36 | 6 | if (!$this->hasIndexConfiguration($indexName)) { |
|
37 | throw new \InvalidArgumentException(sprintf('Index with name "%s" is not configured.', $indexName)); |
||
38 | } |
||
39 | |||
40 | 6 | return $this->indexes[$indexName]; |
|
41 | } |
||
42 | |||
43 | 1 | public function getIndexNames() |
|
44 | 1 | { |
|
45 | return array_keys($this->indexes); |
||
46 | } |
||
47 | |||
48 | 2 | public function getTypeConfiguration($indexName, $typeName) |
|
49 | { |
||
50 | 2 | $index = $this->getIndexConfiguration($indexName); |
|
51 | 2 | $type = $index->getType($typeName); |
|
52 | |||
53 | 2 | if (!$type) { |
|
54 | throw new \InvalidArgumentException(sprintf('Type with name "%s" on index "%s" is not configured', $typeName, $indexName)); |
||
55 | } |
||
56 | |||
57 | 2 | return $type; |
|
58 | } |
||
59 | |||
60 | 6 | public function hasIndexConfiguration($indexName) |
|
64 | } |
||
65 |