Config Source providers
This commit is contained in:
parent
813a4a5d26
commit
ada3942576
12 changed files with 457 additions and 36 deletions
62
Configuration/Source/ContainerSource.php
Normal file
62
Configuration/Source/ContainerSource.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the FOSElasticaBundle project.
|
||||
*
|
||||
* (c) Tim Nagel <tim@nagel.com.au>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace FOS\ElasticaBundle\Configuration\Source;
|
||||
|
||||
use FOS\ElasticaBundle\Configuration\IndexConfig;
|
||||
use FOS\ElasticaBundle\Configuration\TypeConfig;
|
||||
|
||||
/**
|
||||
* Returns index and type configuration from the container.
|
||||
*/
|
||||
class ContainerSource implements SourceInterface
|
||||
{
|
||||
/**
|
||||
* The internal container representation of information.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $configArray;
|
||||
|
||||
public function __construct(array $configArray)
|
||||
{
|
||||
$this->configArray = $configArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should return all configuration available from the data source.
|
||||
*
|
||||
* @return IndexConfig[]
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
$indexes = array();
|
||||
foreach ($this->configArray as $config) {
|
||||
$types = array();
|
||||
foreach ($config['types'] as $typeConfig) {
|
||||
$types[$typeConfig['name']] = new TypeConfig($typeConfig['name'], array(
|
||||
'dynamicTemplates' => $typeConfig['dynamic_templates'],
|
||||
'properties' => $typeConfig['properties'],
|
||||
), $config['type_prototype']);
|
||||
}
|
||||
|
||||
$index = new IndexConfig($config['name'], $types, array(
|
||||
'elasticSearchName' => $config['elasticsearch_name'],
|
||||
'settings' => $config['settings'],
|
||||
'useAlias' => $config['use_alias'],
|
||||
));
|
||||
|
||||
$indexes[$config['name']] = $index;
|
||||
}
|
||||
|
||||
return $indexes;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue