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