Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SearchHandlerInterface #8170

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading