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
|
9 |
|
public function __construct(array $sources) |
28
|
|
|
{ |
29
|
9 |
|
foreach ($sources as $source) { |
30
|
9 |
|
$this->indexes = array_merge($source->getConfiguration(), $this->indexes); |
31
|
|
|
} |
32
|
9 |
|
} |
33
|
|
|
|
34
|
8 |
|
public function getIndexConfiguration(string $indexName): IndexConfigInterface |
35
|
|
|
{ |
36
|
8 |
|
if (!$this->hasIndexConfiguration($indexName)) { |
37
|
|
|
throw new \InvalidArgumentException(sprintf('Index with name "%s" is not configured.', $indexName)); |
38
|
|
|
} |
39
|
|
|
|
40
|
8 |
|
return $this->indexes[$indexName]; |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
public function getIndexNames(): array |
44
|
|
|
{ |
45
|
2 |
|
return array_keys($this->indexes); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getTypeConfiguration(string $indexName, string $typeName): TypeConfig |
49
|
|
|
{ |
50
|
|
|
$index = $this->getIndexConfiguration($indexName); |
51
|
|
|
$type = $index->getType($typeName); |
52
|
|
|
|
53
|
|
|
if (!$type) { |
54
|
|
|
throw new \InvalidArgumentException(sprintf('Type with name "%s" on index "%s" is not configured', $typeName, $indexName)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $type; |
58
|
|
|
} |
59
|
|
|
|
60
|
8 |
|
public function hasIndexConfiguration(string $indexName): bool |
61
|
|
|
{ |
62
|
8 |
|
return isset($this->indexes[$indexName]); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|