From c74f2420502aff95c57036f75ba816ba19a13c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 28 Jul 2020 14:54:16 +0200 Subject: [PATCH] mark search service provider as private --- ChillMainBundle.php | 2 +- Controller/SearchController.php | 64 +++++++++++++------ DependencyInjection/ChillMainExtension.php | 1 + .../SearchableServicesCompilerPass.php | 8 +-- Resources/config/services.yml | 4 -- Resources/config/services/controller.yml | 7 ++ Resources/config/services/form.yml | 2 +- Resources/config/services/search.yml | 3 + Search/SearchProvider.php | 2 +- 9 files changed, 62 insertions(+), 31 deletions(-) rename DependencyInjection/{ => CompilerPass}/SearchableServicesCompilerPass.php (91%) create mode 100644 Resources/config/services/search.yml diff --git a/ChillMainBundle.php b/ChillMainBundle.php index 7cd34037c..abfcdd6fd 100644 --- a/ChillMainBundle.php +++ b/ChillMainBundle.php @@ -4,7 +4,7 @@ namespace Chill\MainBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Chill\MainBundle\DependencyInjection\SearchableServicesCompilerPass; +use Chill\MainBundle\DependencyInjection\CompilerPass\SearchableServicesCompilerPass; use Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\TimelineCompilerClass; use Chill\MainBundle\DependencyInjection\RoleProvidersCompilerPass; diff --git a/Controller/SearchController.php b/Controller/SearchController.php index a56b49d69..c71d7b046 100644 --- a/Controller/SearchController.php +++ b/Controller/SearchController.php @@ -31,15 +31,44 @@ use Chill\MainBundle\Search\SearchInterface; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\HttpFoundation\JsonResponse; +use Chill\MainBundle\Search\SearchProvider; +use Symfony\Component\Translation\TranslatorInterface; +use Chill\MainBundle\Pagination\PaginatorFactory; /** * * - * @author julien.fastre@champs-libres.coop - * @author marc@champs-libres.coop */ class SearchController extends Controller { + /** + * + * @var SearchProvider + */ + protected $searchProvider; + + /** + * + * @var TranslatorInterface + */ + protected $translator; + + /** + * + * @var PaginatorFactory + */ + protected $paginatorFactory; + + function __construct( + SearchProvider $searchProvider, + TranslatorInterface $translator, + PaginatorFactory $paginatorFactory + ) { + $this->searchProvider = $searchProvider; + $this->translator = $translator; + $this->paginatorFactory = $paginatorFactory; + } + public function searchAction(Request $request, $_format) { @@ -50,7 +79,7 @@ class SearchController extends Controller case 'html': return $this->render('ChillMainBundle:Search:error.html.twig', array( - 'message' => $this->get('translator')->trans("Your search is empty. " + 'message' => $this->translator->trans("Your search is empty. " . "Please provide search terms."), 'pattern' => $pattern )); @@ -72,7 +101,7 @@ class SearchController extends Controller } // no specific search selected. Rendering result in "preview" mode - $results = $this->get('chill.main.search_provider') + $results = $this->searchProvider ->getSearchResults( $pattern, 0, @@ -81,17 +110,12 @@ class SearchController extends Controller ); } else { // we want search on a specific search provider. Display full results. - - // create a paginator to get the startPage and stopPage - /* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory */ - $paginatorFactory = $this->get('chill_main.paginator_factory'); - - $results = [$this->get('chill.main.search_provider') + $results = [$this->searchProvider ->getResultByName( $pattern, $name, - $paginatorFactory->getCurrentPageFirstItemNumber(), - $paginatorFactory->getCurrentItemsPerPage(), + $this->paginatorFactory->getCurrentPageFirstItemNumber(), + $this->paginatorFactory->getCurrentItemsPerPage(), array( SearchInterface::SEARCH_PREVIEW_OPTION => false, SearchInterface::REQUEST_QUERY_PARAMETERS => $request @@ -116,8 +140,8 @@ class SearchController extends Controller } catch (ParsingException $ex) { return $this->render('ChillMainBundle:Search:error.html.twig', array( - "message" => $this->get('translator')->trans('Invalid terms'). - ": ".$this->get('translator')->trans($ex->getMessage()), + "message" => $this->translator->trans('Invalid terms'). + ": ".$this->translator->trans($ex->getMessage()), 'pattern' => $pattern )); } @@ -131,7 +155,7 @@ class SearchController extends Controller public function advancedSearchListAction(Request $request) { /* @var $variable Chill\MainBundle\Search\SearchProvider */ - $searchProvider = $this->get('chill.main.search_provider'); + $searchProvider = $this->searchProvider; $advancedSearchProviders = $searchProvider ->getHasAdvancedFormSearchServices(); @@ -150,9 +174,9 @@ class SearchController extends Controller { try { /* @var $variable Chill\MainBundle\Search\SearchProvider */ - $searchProvider = $this->get('chill.main.search_provider'); + $searchProvider = $this->searchProvider; /* @var $variable Chill\MainBundle\Search\HasAdvancedSearchFormInterface */ - $search = $this->get('chill.main.search_provider') + $search = $this->searchProvider ->getHasAdvancedFormByName($name); } catch (\Chill\MainBundle\Search\UnknowSearchNameException $e) { @@ -171,7 +195,7 @@ class SearchController extends Controller $form->handleRequest($request); if ($form->isValid()) { - $pattern = $this->get('chill.main.search_provider') + $pattern = $this->searchProvider ->getHasAdvancedFormByName($name) ->convertFormDataToQuery($form->getData()); @@ -194,13 +218,13 @@ class SearchController extends Controller $builder = $this ->get('form.factory') ->createNamedBuilder( - null, + null, FormType::class, $data, [ 'method' => Request::METHOD_POST ] ); - $this->get('chill.main.search_provider') + $this->searchProvider ->getHasAdvancedFormByName($name) ->buildForm($builder) ; diff --git a/DependencyInjection/ChillMainExtension.php b/DependencyInjection/ChillMainExtension.php index 92092d889..d293cd562 100644 --- a/DependencyInjection/ChillMainExtension.php +++ b/DependencyInjection/ChillMainExtension.php @@ -121,6 +121,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $loader->load('services/cache.yml'); $loader->load('services/templating.yml'); $loader->load('services/timeline.yml'); + $loader->load('services/search.yml'); $this->configureCruds($container, $config['cruds'], $loader); } diff --git a/DependencyInjection/SearchableServicesCompilerPass.php b/DependencyInjection/CompilerPass/SearchableServicesCompilerPass.php similarity index 91% rename from DependencyInjection/SearchableServicesCompilerPass.php rename to DependencyInjection/CompilerPass/SearchableServicesCompilerPass.php index 12f27933e..e07849ed2 100644 --- a/DependencyInjection/SearchableServicesCompilerPass.php +++ b/DependencyInjection/CompilerPass/SearchableServicesCompilerPass.php @@ -18,7 +18,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -namespace Chill\MainBundle\DependencyInjection; +namespace Chill\MainBundle\DependencyInjection\CompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -33,13 +33,13 @@ class SearchableServicesCompilerPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - if (!$container->hasDefinition('chill.main.search_provider')) { - throw new \LogicException('service chill.main.search_provider ' + if (!$container->hasDefinition('chill_main.search_provider')) { + throw new \LogicException('service chill_main.search_provider ' . 'is not defined.'); } $definition = $container->getDefinition( - 'chill.main.search_provider' + 'chill_main.search_provider' ); $taggedServices = $container->findTaggedServiceIds( diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 3f2c59506..93a4ee4e4 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -37,10 +37,6 @@ services: arguments: - "@doctrine.orm.entity_manager" - chill.main.search_provider: - class: Chill\MainBundle\Search\SearchProvider - public: true - chill.main.validator.role_scope_scope_presence: class: Chill\MainBundle\Validation\Validator\RoleScopeScopePresence arguments: diff --git a/Resources/config/services/controller.yml b/Resources/config/services/controller.yml index 562753837..a62470777 100644 --- a/Resources/config/services/controller.yml +++ b/Resources/config/services/controller.yml @@ -10,3 +10,10 @@ services: arguments: $chillLogger: '@monolog.logger.chill' tags: ['controller.service_arguments'] + + Chill\MainBundle\Controller\SearchController: + arguments: + $searchProvider: '@chill_main.search_provider' + $translator: '@Symfony\Component\Translation\TranslatorInterface' + $paginatorFactory: '@Chill\MainBundle\Pagination\PaginatorFactory' + tags: ['controller.service_arguments'] diff --git a/Resources/config/services/form.yml b/Resources/config/services/form.yml index 35d527726..865e495d8 100644 --- a/Resources/config/services/form.yml +++ b/Resources/config/services/form.yml @@ -123,7 +123,7 @@ services: chill.main.form.advanced_search_type: class: Chill\MainBundle\Form\AdvancedSearchType arguments: - - "@chill.main.search_provider" + - "@chill_main.search_provider" tags: - { name: form.type } diff --git a/Resources/config/services/search.yml b/Resources/config/services/search.yml new file mode 100644 index 000000000..e8a457415 --- /dev/null +++ b/Resources/config/services/search.yml @@ -0,0 +1,3 @@ +services: + chill_main.search_provider: + class: Chill\MainBundle\Search\SearchProvider \ No newline at end of file diff --git a/Search/SearchProvider.php b/Search/SearchProvider.php index f85343348..e95cab4d2 100644 --- a/Search/SearchProvider.php +++ b/Search/SearchProvider.php @@ -9,7 +9,7 @@ use Chill\MainBundle\Search\HasAdvancedSearchFormInterface; * a service which gather all search services defined into the bundles * installed into the app. * the service is callable from the container with - * $container->get('chill.main.search_provider') + * $container->get('chill_main.search_provider') * * the syntax for search string is : * - domain, which begin with `@`. Example: `@person`. Restrict the search to some