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