1 | <?php |
||
20 | class SearchService |
||
21 | { |
||
22 | /** |
||
23 | * @var RenderContext |
||
24 | */ |
||
25 | protected $renderContext; |
||
26 | |||
27 | /** |
||
28 | * @var Container |
||
29 | */ |
||
30 | protected $container; |
||
31 | |||
32 | /** |
||
33 | * @var RequestStack |
||
34 | */ |
||
35 | protected $requestStack; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $defaultPerPage; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $searchers; |
||
46 | |||
47 | /** |
||
48 | * @param ContainerInterface $container |
||
49 | * @param RequestStack $requestStack |
||
50 | * @param int $defaultPerPage |
||
51 | * @param array $searchers |
||
52 | */ |
||
53 | 2 | public function __construct(ContainerInterface $container, RequestStack $requestStack, $defaultPerPage = 10, array $searchers = []) |
|
61 | |||
62 | /** |
||
63 | * @param int $defaultPerPage |
||
64 | */ |
||
65 | public function setDefaultPerPage($defaultPerPage) |
||
69 | |||
70 | /** |
||
71 | * @return RenderContext |
||
72 | */ |
||
73 | public function getRenderContext() |
||
77 | |||
78 | /** |
||
79 | * @param RenderContext $renderContext |
||
80 | */ |
||
81 | public function setRenderContext($renderContext) |
||
85 | |||
86 | /** |
||
87 | * @return int |
||
88 | */ |
||
89 | 1 | public function getDefaultPerPage() |
|
93 | |||
94 | /** |
||
95 | * @return Container |
||
96 | */ |
||
97 | public function getContainer() |
||
101 | |||
102 | /** |
||
103 | * @param Container $container |
||
104 | */ |
||
105 | public function setContainer($container) |
||
109 | |||
110 | /** |
||
111 | * @return Request |
||
112 | */ |
||
113 | public function getRequest() |
||
117 | |||
118 | /** |
||
119 | * @return Pagerfanta |
||
120 | */ |
||
121 | 2 | public function search() |
|
122 | { |
||
123 | 2 | $request = $this->requestStack->getCurrentRequest(); |
|
124 | |||
125 | // Retrieve the current page number from the URL, if not present of lower than 1, set it to 1 |
||
126 | 2 | $entity = $request->attributes->get('_entity'); |
|
127 | |||
128 | 2 | $pageNumber = $this->getRequestedPage($request); |
|
129 | |||
130 | 2 | $searcher = $this->searchers[$entity->getSearcher()] ?? null; |
|
131 | 2 | if (null === $searcher) { |
|
132 | 2 | $searcher = $this->container->get($entity->getSearcher()); |
|
133 | |||
134 | 1 | @trigger_error( |
|
135 | sprintf( |
||
136 | 1 | 'Getting the node searcher "%s" from the container is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Tag your searcher service with the "kunstmaan_node_search.node_searcher" tag to add a searcher.', |
|
137 | 1 | $entity->getSearcher() |
|
138 | ), |
||
139 | 1 | E_USER_DEPRECATED |
|
140 | ); |
||
141 | } |
||
142 | |||
143 | 1 | $this->applySearchParams($searcher, $request, $this->renderContext); |
|
144 | |||
145 | 1 | $adapter = new SearcherRequestAdapter($searcher); |
|
146 | 1 | $pagerfanta = new Pagerfanta($adapter); |
|
147 | |||
148 | try { |
||
149 | $pagerfanta |
||
150 | 1 | ->setMaxPerPage($this->getDefaultPerPage()) |
|
151 | 1 | ->setCurrentPage($pageNumber); |
|
152 | } catch (NotValidCurrentPageException $e) { |
||
153 | throw new NotFoundHttpException(); |
||
154 | } |
||
155 | |||
156 | 1 | return $pagerfanta; |
|
157 | } |
||
158 | |||
159 | /** |
||
160 | * @param AbstractElasticaSearcher $searcher |
||
161 | * @param Request $request |
||
162 | * @param RenderContext $context |
||
163 | */ |
||
164 | 1 | protected function applySearchParams(AbstractElasticaSearcher $searcher, Request $request, RenderContext $context) |
|
187 | |||
188 | /** |
||
189 | * Currently we just search for a complete match... |
||
190 | * |
||
191 | * @param string $query |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | 1 | protected function sanitizeSearchQuery($query) |
|
199 | |||
200 | /** |
||
201 | * @param Request $request |
||
202 | * |
||
203 | * @return int |
||
204 | */ |
||
205 | 2 | private function getRequestedPage(Request $request) |
|
214 | } |
||
215 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.