440c36f537
Conflicts: Command/PopulateCommand.php Command/SearchCommand.php DependencyInjection/Configuration.php Doctrine/AbstractElasticaToModelTransformer.php Doctrine/AbstractListener.php Doctrine/MongoDB/ElasticaToModelTransformer.php Doctrine/ORM/ElasticaToModelTransformer.php Doctrine/RepositoryManager.php Finder/TransformedFinder.php Paginator/PaginatorAdapterInterface.php Paginator/RawPaginatorAdapter.php Persister/ObjectPersister.php Propel/ElasticaToModelTransformer.php Subscriber/PaginateElasticaQuerySubscriber.php Tests/DataCollector/ElasticaDataCollectorTest.php Tests/Doctrine/AbstractProviderTest.php Tests/Doctrine/RepositoryManagerTest.php Tests/Manager/RepositoryManagerTest.php Tests/RepositoryTest.php Transformer/ElasticaToModelTransformerCollection.php composer.json
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace FOS\ElasticaBundle;
|
|
|
|
class IndexManager
|
|
{
|
|
protected $indexesByName;
|
|
protected $defaultIndexName;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param array $indexesByName
|
|
* @param \Elastica_Index $defaultIndex
|
|
*/
|
|
public function __construct(array $indexesByName, \Elastica_Index $defaultIndex)
|
|
{
|
|
$this->indexesByName = $indexesByName;
|
|
$this->defaultIndexName = $defaultIndex->getName();
|
|
}
|
|
|
|
/**
|
|
* Gets all registered indexes
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getAllIndexes()
|
|
{
|
|
return $this->indexesByName;
|
|
}
|
|
|
|
/**
|
|
* Gets an index by its name
|
|
*
|
|
* @param string $name Index to return, or the default index if null
|
|
* @return \Elastica_Index
|
|
* @throws \InvalidArgumentException if no index exists for the given name
|
|
*/
|
|
public function getIndex($name = null)
|
|
{
|
|
if (null === $name) {
|
|
$name = $this->defaultIndexName;
|
|
}
|
|
|
|
if (!isset($this->indexesByName[$name])) {
|
|
throw new \InvalidArgumentException(sprintf('The index "%s" does not exist', $name));
|
|
}
|
|
|
|
return $this->indexesByName[$name];
|
|
}
|
|
|
|
/**
|
|
* Gets the default index
|
|
*
|
|
* @return \Elastica_Index
|
|
*/
|
|
public function getDefaultIndex()
|
|
{
|
|
return $this->getIndex($this->defaultIndexName);
|
|
}
|
|
}
|