Merge branch 'search' into dev
This commit is contained in:
@@ -5,14 +5,20 @@ use App\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\Handlers\Contracts\SearchHandler;
|
||||
use App\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\Handlers\Registrators\Items\SearchEngine;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
|
||||
class SearchEngineRegistrator
|
||||
{
|
||||
const ADMIN = 'admin';
|
||||
const VISITOR = 'visitor';
|
||||
protected $searchEngines;
|
||||
|
||||
function __construct($app)
|
||||
{
|
||||
$this->searchEngines = [];
|
||||
$this->searchEngines = [
|
||||
self::ADMIN => [],
|
||||
self::VISITOR => []
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,37 +27,46 @@ class SearchEngineRegistrator
|
||||
* @param SearchHandler $search
|
||||
* @param SearchPresenterHandler $presenter
|
||||
*
|
||||
* @param $type
|
||||
*
|
||||
* @throws EnumerationExistsException
|
||||
*/
|
||||
public function register(SearchHandler $search, SearchPresenterHandler $presenter)
|
||||
public function register(SearchHandler $search, SearchPresenterHandler $presenter, $type)
|
||||
{
|
||||
$this->checkIfRegistered($search->getId());
|
||||
$this->checkIfRegistered($type, $search->getId());
|
||||
|
||||
// register new extension
|
||||
$this->searchEngines[$search->getId()] = [$search, $presenter];
|
||||
$this->searchEngines[$type][$search->getId()] = [$search, $presenter];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for all registered extensions
|
||||
*
|
||||
* @param $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
public function get($type)
|
||||
{
|
||||
return $this->searchEngines;
|
||||
if (!isset($this->searchEngines[$type])) {
|
||||
throw new InvalidArgumentException('Invalid type ' . $type);
|
||||
}
|
||||
|
||||
return $this->searchEngines[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this section is not already defined
|
||||
*
|
||||
* @param $type
|
||||
* @param $id
|
||||
*
|
||||
* @throws EnumerationExistsException
|
||||
*/
|
||||
private function checkIfRegistered($id)
|
||||
private function checkIfRegistered($type, $id)
|
||||
{
|
||||
if (isset($this->searchEngines[$id])) {
|
||||
throw new EnumerationExistsException('Already existing search engine ' . $id);
|
||||
if (isset($this->searchEngines[$type][$id])) {
|
||||
throw new EnumerationExistsException('Already existing search engine ' . $id . ' in ' . $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user