1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace FactorioItemBrowser \Api \Client \Request \Search ;
6+
7+ use FactorioItemBrowser \Api \Client \Request \RequestInterface ;
8+ use FactorioItemBrowser \Api \Client \Response \AbstractResponse ;
9+ use FactorioItemBrowser \Api \Client \Response \PendingResponse ;
10+ use FactorioItemBrowser \Api \Client \Response \Search \SearchQueryResponse ;
11+
12+ /**
13+ * The request for the search query.
14+ *
15+ * @author BluePsyduck <[email protected] > 16+ * @license http://opensource.org/licenses/GPL-3.0 GPL v3
17+ */
18+ class SearchQueryRequest implements RequestInterface
19+ {
20+ /**
21+ * The query to search for.
22+ * @var string
23+ */
24+ protected $ query = '' ;
25+
26+ /**
27+ * The number of results to return.
28+ * @var int
29+ */
30+ protected $ numberOfResults = 10 ;
31+
32+ /**
33+ * The 0-based index of the first result to return.
34+ * @var int
35+ */
36+ protected $ indexOfFirstResult = 0 ;
37+
38+ /**
39+ * The number pf recipes to return for each result.
40+ * @var int
41+ */
42+ protected $ numberOfRecipesPerResult = 3 ;
43+
44+ /**
45+ * Sets the query to search for.
46+ * @param string $query
47+ * @return $this
48+ */
49+ public function setQuery (string $ query )
50+ {
51+ $ this ->query = $ query ;
52+ return $ this ;
53+ }
54+
55+ /**
56+ * Sets the number of results to return.
57+ * @param int $numberOfResults
58+ * @return $this
59+ */
60+ public function setNumberOfResults (int $ numberOfResults )
61+ {
62+ $ this ->numberOfResults = $ numberOfResults ;
63+ return $ this ;
64+ }
65+
66+ /**
67+ * Sets the 0-based index of the first result to return.
68+ * @param int $indexOfFirstResult
69+ * @return $this
70+ */
71+ public function setIndexOfFirstResult (int $ indexOfFirstResult )
72+ {
73+ $ this ->indexOfFirstResult = $ indexOfFirstResult ;
74+ return $ this ;
75+ }
76+
77+ /**
78+ * Sets the number pf recipes to return for each result.
79+ * @param int $numberOfRecipesPerResult
80+ * @return $this
81+ */
82+ public function setNumberOfRecipesPerResult (int $ numberOfRecipesPerResult )
83+ {
84+ $ this ->numberOfRecipesPerResult = $ numberOfRecipesPerResult ;
85+ return $ this ;
86+ }
87+
88+ /**
89+ * Returns the path of the request, relative to the API URL.
90+ * @return string
91+ */
92+ public function getRequestPath (): string
93+ {
94+ return '/search/query ' ;
95+ }
96+
97+ /**
98+ * Returns the actual data of the request.
99+ * @return array
100+ */
101+ public function getRequestData (): array
102+ {
103+ return [
104+ 'query ' => $ this ->query ,
105+ 'numberOfResults ' => $ this ->numberOfResults ,
106+ 'indexOfFirstResult ' => $ this ->indexOfFirstResult ,
107+ 'numberOfRecipesPerResult ' => $ this ->numberOfRecipesPerResult
108+ ];
109+ }
110+
111+ /**
112+ * Creates the response instance matching the request.
113+ * @param PendingResponse $pendingResponse
114+ * @return AbstractResponse
115+ */
116+ public function createResponse (PendingResponse $ pendingResponse ): AbstractResponse
117+ {
118+ return new SearchQueryResponse ($ pendingResponse );
119+ }
120+ }
0 commit comments