FOSElasticaBundle/Index/IndexManager.php

66 lines
1.3 KiB
PHP
Raw Normal View History

2014-04-21 01:21:50 +02:00
<?php
namespace FOS\ElasticaBundle\Index;
2014-06-17 15:22:58 +02:00
use FOS\ElasticaBundle\Elastica\Index;
2014-04-21 01:21:50 +02:00
class IndexManager
{
/**
* @var array
*/
private $indexes;
2014-04-21 01:21:50 +02:00
/**
* @param array $indexes
2014-04-21 01:21:50 +02:00
* @param Index $defaultIndex
*/
public function __construct(array $indexes, Index $defaultIndex)
2014-04-21 01:21:50 +02:00
{
$this->defaultIndex = $defaultIndex;
$this->indexes = $indexes;
2014-04-21 01:21:50 +02:00
}
/**
2015-03-12 11:20:00 +01:00
* Gets all registered indexes.
2014-04-21 01:21:50 +02:00
*
* @return array
*/
public function getAllIndexes()
{
return $this->indexes;
2014-04-21 01:21:50 +02:00
}
/**
2015-03-12 11:20:00 +01:00
* Gets an index by its name.
2014-04-21 01:21:50 +02:00
*
* @param string $name Index to return, or the default index if null
2015-03-12 11:20:00 +01:00
*
2014-04-21 01:21:50 +02:00
* @return Index
2015-03-12 11:20:00 +01:00
*
2014-04-21 01:21:50 +02:00
* @throws \InvalidArgumentException if no index exists for the given name
*/
public function getIndex($name = null)
{
if (null === $name) {
return $this->defaultIndex;
2014-04-21 01:21:50 +02:00
}
if (!isset($this->indexes[$name])) {
2014-04-21 01:21:50 +02:00
throw new \InvalidArgumentException(sprintf('The index "%s" does not exist', $name));
}
return $this->indexes[$name];
2014-04-21 01:21:50 +02:00
}
/**
2015-03-12 11:20:00 +01:00
* Gets the default index.
2014-04-21 01:21:50 +02:00
*
* @return Index
*/
public function getDefaultIndex()
{
return $this->defaultIndex;
2014-04-21 01:21:50 +02:00
}
}