FEATURE: add registering for new search engines.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace App\Handlers\Registrators;
|
||||
|
||||
use App\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\Handlers\Contracts\SearchHandler;
|
||||
use App\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\Handlers\Registrators\Items\SearchEngine;
|
||||
|
||||
class SearchEngineRegistrator
|
||||
{
|
||||
protected $searchEngines;
|
||||
|
||||
function __construct($app)
|
||||
{
|
||||
$this->searchEngines = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for registering new settings extensions/parts
|
||||
*
|
||||
* @param SearchHandler $search
|
||||
* @param SearchPresenterHandler $presenter
|
||||
*
|
||||
* @throws EnumerationExistsException
|
||||
*/
|
||||
public function register(SearchHandler $search, SearchPresenterHandler $presenter)
|
||||
{
|
||||
$this->checkIfRegistered($search->getId());
|
||||
|
||||
// register new extension
|
||||
$this->searchEngines[$search->getId()] = [$search, $presenter];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for all registered extensions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return $this->searchEngines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this section is not already defined
|
||||
*
|
||||
* @param $id
|
||||
*
|
||||
* @throws EnumerationExistsException
|
||||
*/
|
||||
private function checkIfRegistered($id)
|
||||
{
|
||||
if (isset($this->searchEngines[$id])) {
|
||||
throw new EnumerationExistsException('Already existing search engine ' . $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user