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 1716254
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 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
9 changes: 1 addition & 8 deletions src/Search/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@
/**
* @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
19 changes: 19 additions & 0 deletions src/Search/SearchHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

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 1716254

Please sign in to comment.