From 62eebc33813b5d1c32953e1842568b07bad550be Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 9 Apr 2024 10:41:11 +0200 Subject: [PATCH] Introduce SearchHandlerInterface --- src/Block/AdminSearchBlockService.php | 4 ++-- src/Resources/config/core.php | 3 +++ src/Search/SearchHandler.php | 10 +-------- src/Search/SearchHandlerInterface.php | 30 +++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 src/Search/SearchHandlerInterface.php diff --git a/src/Block/AdminSearchBlockService.php b/src/Block/AdminSearchBlockService.php index 372a55b96d..674715ef7e 100644 --- a/src/Block/AdminSearchBlockService.php +++ b/src/Block/AdminSearchBlockService.php @@ -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; @@ -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 diff --git a/src/Resources/config/core.php b/src/Resources/config/core.php index f57a51cf67..3ff2683220 100644 --- a/src/Resources/config/core.php +++ b/src/Resources/config/core.php @@ -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; @@ -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') diff --git a/src/Search/SearchHandler.php b/src/Search/SearchHandler.php index 36e4af2008..0432542977 100644 --- a/src/Search/SearchHandler.php +++ b/src/Search/SearchHandler.php @@ -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 */ -final class SearchHandler +final class SearchHandler implements SearchHandlerInterface { /** * @var array */ private array $adminsSearchConfig = []; - /** - * @throws \RuntimeException - * - * @phpstan-template T of object - * @phpstan-param AdminInterface $admin - * @phpstan-return PagerInterface>|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. diff --git a/src/Search/SearchHandlerInterface.php b/src/Search/SearchHandlerInterface.php new file mode 100644 index 0000000000..c4dbfcee2d --- /dev/null +++ b/src/Search/SearchHandlerInterface.php @@ -0,0 +1,30 @@ + + * + * 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 $admin + * @phpstan-return PagerInterface>|null + */ + public function search(AdminInterface $admin, string $term, int $page = 0, int $offset = 20): ?PagerInterface; +}