|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace FOS\ElasticaBundle\Configuration; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Central manager for index and type configuration. |
|
16
|
|
|
*/ |
|
17
|
|
|
class ConfigManager implements ManagerInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var IndexConfig[] |
|
21
|
|
|
*/ |
|
22
|
|
|
private $indexes = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param Source\SourceInterface[] $sources |
|
26
|
|
|
*/ |
|
27
|
8 |
|
public function __construct(array $sources) |
|
28
|
|
|
{ |
|
29
|
8 |
|
foreach ($sources as $source) { |
|
30
|
8 |
|
$this->indexes = array_merge($source->getConfiguration(), $this->indexes); |
|
31
|
|
|
} |
|
32
|
8 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param string $indexName |
|
36
|
|
|
* |
|
37
|
|
|
* @return IndexConfig |
|
38
|
|
|
*/ |
|
39
|
6 |
|
public function getIndexConfiguration($indexName) |
|
40
|
|
|
{ |
|
41
|
6 |
|
if (!$this->hasIndexConfiguration($indexName)) { |
|
42
|
|
|
throw new \InvalidArgumentException(sprintf('Index with name "%s" is not configured.', $indexName)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
6 |
|
return $this->indexes[$indexName]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function getIndexNames() |
|
52
|
|
|
{ |
|
53
|
2 |
|
return array_keys($this->indexes); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getTypeConfiguration($indexName, $typeName) |
|
60
|
|
|
{ |
|
61
|
|
|
$index = $this->getIndexConfiguration($indexName); |
|
62
|
|
|
$type = $index->getType($typeName); |
|
63
|
|
|
|
|
64
|
|
|
if (!$type) { |
|
65
|
|
|
throw new \InvalidArgumentException(sprintf('Type with name "%s" on index "%s" is not configured', $typeName, $indexName)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $type; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $indexName |
|
73
|
|
|
* |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
6 |
|
public function hasIndexConfiguration($indexName) |
|
77
|
|
|
{ |
|
78
|
6 |
|
return isset($this->indexes[$indexName]); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|