Skip to content

Commit

Permalink
Introduce SearchHandlerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 9, 2024
1 parent 247131e commit b963d37
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Block/AdminSearchBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Filter\FilterInterface;
use Sonata\AdminBundle\Search\SearchableFilterInterface;
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\AdminBundle\Search\SearchHandlerInterface;
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
Expand All @@ -37,7 +37,7 @@ final class AdminSearchBlockService extends AbstractBlockService
public function __construct(
Environment $twig,
private Pool $pool,
private SearchHandler $searchHandler,
private SearchHandlerInterface $searchHandler,
private TemplateRegistryInterface $templateRegistry,
private string $emptyBoxesOption,
private string $adminRoute
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Sonata\AdminBundle\Request\AdminFetcherInterface;
use Sonata\AdminBundle\Route\AdminPoolLoader;
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\AdminBundle\Search\SearchHandlerInterface;
use Sonata\AdminBundle\SonataConfiguration;
use Sonata\AdminBundle\Templating\TemplateRegistry;
use Sonata\AdminBundle\Translator\BCLabelTranslatorStrategy;
Expand Down Expand Up @@ -124,6 +125,8 @@

->set('sonata.admin.search.handler', SearchHandler::class)

->alias(SearchHandlerInterface::class, 'sonata.admin.search.handler')

->set('sonata.admin.controller.crud', CRUDController::class)
->public()
->tag('container.service_subscriber')
Expand Down
10 changes: 1 addition & 9 deletions src/Search/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,18 @@

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\PagerInterface;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Filter\FilterInterface;

/**
* @author Thomas Rabaix <[email protected]>
*/
final class SearchHandler
final class SearchHandler implements SearchHandlerInterface
{
/**
* @var array<string, bool>
*/
private array $adminsSearchConfig = [];

/**
* @throws \RuntimeException
*
* @phpstan-template T of object
* @phpstan-param AdminInterface<T> $admin
* @phpstan-return PagerInterface<ProxyQueryInterface<T>>|null
*/
public function search(AdminInterface $admin, string $term, int $page = 0, int $offset = 20): ?PagerInterface
{
// If the search is disabled for the whole admin, skip any further processing.
Expand Down
30 changes: 30 additions & 0 deletions src/Search/SearchHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Search;

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\PagerInterface;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;

interface SearchHandlerInterface
{
/**
* @throws \RuntimeException
*
* @phpstan-template T of object
* @phpstan-param AdminInterface<T> $admin
* @phpstan-return PagerInterface<ProxyQueryInterface<T>>|null
*/
public function search(AdminInterface $admin, string $term, int $page = 0, int $offset = 20): ?PagerInterface;
}

0 comments on commit b963d37

Please sign in to comment.