|
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\Source; |
|
22
|
|
|
|
|
23
|
|
|
use FOS\ElasticaBundle\Configuration\IndexConfig; |
|
24
|
|
|
use FOS\ElasticaBundle\Configuration\TypeConfig; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Returns index and type configuration from the container. |
|
28
|
|
|
*/ |
|
29
|
|
|
class ContainerSource implements SourceInterface |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* The internal container representation of information. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
private $configArray; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param array $configArray |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(array $configArray) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->configArray = $configArray; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Should return all configuration available from the data source. |
|
48
|
|
|
* |
|
49
|
|
|
* @return IndexConfig[] |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getConfiguration() |
|
52
|
|
|
{ |
|
53
|
|
|
$indexes = []; |
|
54
|
|
|
foreach ($this->configArray as $config) { |
|
55
|
|
|
$types = $this->getTypes($config); |
|
56
|
|
|
$index = new IndexConfig($config['name'], $types, [ |
|
57
|
|
|
'elasticSearchName' => $config['elasticsearch_name'], |
|
58
|
|
|
'settings' => $config['settings'], |
|
59
|
|
|
'useAlias' => $config['use_alias'], |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
$indexes[$config['name']] = $index; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $indexes; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Builds TypeConfig objects for each type. |
|
70
|
|
|
* |
|
71
|
|
|
* @param array $config |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function getTypes($config) |
|
76
|
|
|
{ |
|
77
|
|
|
$types = []; |
|
78
|
|
|
|
|
79
|
|
|
if (isset($config['types'])) { |
|
80
|
|
|
foreach ($config['types'] as $typeConfig) { |
|
81
|
|
|
$types[$typeConfig['name']] = new TypeConfig( |
|
82
|
|
|
$typeConfig['name'], |
|
83
|
|
|
$typeConfig['mapping'], |
|
84
|
|
|
$typeConfig['config'] |
|
85
|
|
|
); |
|
86
|
|
|
// TODO: handle prototypes.. |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $types; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|