FOSElasticaBundle/IndexManager.php

55 lines
1 KiB
PHP
Raw Normal View History

<?php
namespace FOQ\ElasticaBundle;
2011-04-13 00:15:48 +02:00
use InvalidArgumentException;
class IndexManager
{
protected $indexes;
2011-04-13 00:15:48 +02:00
protected $defaultIndex;
2011-04-13 00:15:48 +02:00
public function __construct(array $indexes, $defaultIndex)
{
2011-04-13 00:15:48 +02:00
$this->indexes = $indexes;
$this->defaultIndex = $defaultIndex;
}
/**
* Gets all registered indexes
*
* @return array
*/
public function getAllIndexes()
{
return $this->indexes;
}
/**
2011-04-13 00:15:48 +02:00
* Gets an index by its name
*
2011-04-13 00:15:48 +02:00
* @return Elastica_Index
**/
public function getIndex($name)
{
2011-04-13 00:15:48 +02:00
if (!$name) {
return $this->getDefaultIndex();
}
if (!isset($this->indexes[$name])) {
throw new InvalidArgumentException(sprintf('The index "%s" does not exist', $name));
}
2011-04-13 00:15:48 +02:00
return $this->indexes[$name];
}
/**
* Gets the default index
*
* @return Elastica_Index
**/
public function getDefaultIndex()
{
return $this->defaultIndex;
}
}