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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Handlers\Contracts\SearchHandler;
|
||||
use App\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\Handlers\Registrators\SearchEngineRegistrator;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use Illuminate\Support\Facades\App;
|
||||
@@ -48,7 +49,7 @@ class Search extends Controller
|
||||
protected function performSearch($term)
|
||||
{
|
||||
$engines = App::make('registerSearchEngine')
|
||||
->get();
|
||||
->get(SearchEngineRegistrator::ADMIN);
|
||||
|
||||
$resultsParts = [];
|
||||
foreach ($engines as $engine) {
|
||||
|
||||
@@ -119,8 +119,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
$registrator = $this->app->make('registerSearchEngine');
|
||||
|
||||
$registrator->register(new Content(), new AdminContentPresenter());
|
||||
$registrator->register(new Files(), new AdminFiles());
|
||||
$registrator->register(new Content(), new AdminContentPresenter(), SearchEngineRegistrator::ADMIN);
|
||||
$registrator->register(new Files(), new AdminFiles(), SearchEngineRegistrator::ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user