| @@ 20-83 (lines=64) @@ | ||
| 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 | /**  | 
                                |
| 30 | * @param array $configArray  | 
                                |
| 31 | */  | 
                                |
| 32 | public function __construct(array $configArray)  | 
                                |
| 33 |     { | 
                                |
| 34 | $this->configArray = $configArray;  | 
                                |
| 35 | }  | 
                                |
| 36 | ||
| 37 | /**  | 
                                |
| 38 | * Should return all configuration available from the data source.  | 
                                |
| 39 | *  | 
                                |
| 40 | * @return IndexConfig[]  | 
                                |
| 41 | */  | 
                                |
| 42 | public function getConfiguration()  | 
                                |
| 43 |     { | 
                                |
| 44 | $indexes = [];  | 
                                |
| 45 |         foreach ($this->configArray as $config) { | 
                                |
| 46 | $types = $this->getTypes($config);  | 
                                |
| 47 | $index = new IndexConfig($config['name'], $types, [  | 
                                |
| 48 | 'elasticSearchName' => $config['elasticsearch_name'],  | 
                                |
| 49 | 'settings' => $config['settings'],  | 
                                |
| 50 | 'useAlias' => $config['use_alias'],  | 
                                |
| 51 | ]);  | 
                                |
| 52 | ||
| 53 | $indexes[$config['name']] = $index;  | 
                                |
| 54 | }  | 
                                |
| 55 | ||
| 56 | return $indexes;  | 
                                |
| 57 | }  | 
                                |
| 58 | ||
| 59 | /**  | 
                                |
| 60 | * Builds TypeConfig objects for each type.  | 
                                |
| 61 | *  | 
                                |
| 62 | * @param array $config  | 
                                |
| 63 | *  | 
                                |
| 64 | * @return array  | 
                                |
| 65 | */  | 
                                |
| 66 | protected function getTypes($config)  | 
                                |
| 67 |     { | 
                                |
| 68 | $types = [];  | 
                                |
| 69 | ||
| 70 |         if (isset($config['types'])) { | 
                                |
| 71 |             foreach ($config['types'] as $typeConfig) { | 
                                |
| 72 | $types[$typeConfig['name']] = new TypeConfig(  | 
                                |
| 73 | $typeConfig['name'],  | 
                                |
| 74 | $typeConfig['mapping'],  | 
                                |
| 75 | $typeConfig['config']  | 
                                |
| 76 | );  | 
                                |
| 77 | // TODO: handle prototypes..  | 
                                |
| 78 | }  | 
                                |
| 79 | }  | 
                                |
| 80 | ||
| 81 | return $types;  | 
                                |
| 82 | }  | 
                                |
| 83 | }  | 
                                |
| 84 | ||
| @@ 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 | ||