| 1 | <?php |
||
| 14 | abstract class AbstractSearchDomain |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Human-readable name of the search domain |
||
| 18 | * |
||
| 19 | * Ideally, this is loaded dynamically from the domain via API -- and any |
||
| 20 | * dynamic result will override any preset configuration. |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $name; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * URL of the search domain's home page |
||
| 27 | * |
||
| 28 | * Ideally, this is loaded or constructed dynamically via API -- and any |
||
| 29 | * dynamic result will override any preset configuration. |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $url; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * URL of the search domain's icon |
||
| 36 | * |
||
| 37 | * This will be rendered 16x16 pixels when displayed. |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $icon; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Construct a SearchDomain |
||
| 44 | * |
||
| 45 | * Parameters are passed to this constuctor as an associative array of values, including, at a minimum: |
||
| 46 | * |
||
| 47 | * ``` |
||
| 48 | * [ |
||
| 49 | * 'name' => 'A human-readable name for the domain', |
||
| 50 | * 'url' => 'URL of the home page of the domain' |
||
| 51 | * ] |
||
| 52 | * ``` |
||
| 53 | * |
||
| 54 | * Subclasses may (and will) add additional required parameters to that |
||
| 55 | * list. |
||
| 56 | * |
||
| 57 | * @param mixed[] $params |
||
| 58 | * |
||
| 59 | * @throws Exception If `$params['url']` is not a valid URL or |
||
| 60 | * `$params['name']` is empty. |
||
| 61 | */ |
||
| 62 | public function __construct($params) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Update the URL of the search domain |
||
| 77 | * |
||
| 78 | * @used-by AbstractSearchDomain::__construct() |
||
| 79 | * @param string $url |
||
| 80 | * @throws Exception If `$url` is empty or is not a valid URL |
||
| 81 | */ |
||
| 82 | protected function setUrl($url) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Set the name of the search domain |
||
| 94 | * |
||
| 95 | * @used-by AbstractSearchDomain::__construct() |
||
| 96 | * @param string $name |
||
| 97 | * @throws Exception If `$name` is empty |
||
| 98 | */ |
||
| 99 | protected function setName($name) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Set the icon URL for the search domain |
||
| 110 | * |
||
| 111 | * Does nothing if `$url` is not a valid URL |
||
| 112 | * |
||
| 113 | * @used-by AbstractSearchDomain::__construct() |
||
| 114 | * @param string $icon |
||
| 115 | */ |
||
| 116 | protected function setIcon($icon) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Search within this domain |
||
| 125 | * |
||
| 126 | * @param string $query |
||
| 127 | * @return SearchResult[] Ordered by descending relevance |
||
| 128 | */ |
||
| 129 | abstract public function search($query); |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Sort into order of descending relevance |
||
| 133 | * |
||
| 134 | * @param SearchResult[] $results |
||
| 135 | * @return void |
||
| 136 | */ |
||
| 137 | protected function sortByRelevance(&$results) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Human-readable name of the search domain |
||
| 152 | * |
||
| 153 | * @return string |
||
| 154 | */ |
||
| 155 | public function getName() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * URL of the home page of the search domain |
||
| 162 | * |
||
| 163 | * @return string |
||
| 164 | */ |
||
| 165 | public function getUrl() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * URL of the icon of this search domain |
||
| 172 | * |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 175 | public function getIcon() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Force a boolean result from a particular parameter key |
||
| 182 | * |
||
| 183 | * @param mixed[string] $params |
||
|
1 ignored issue
–
show
|
|||
| 184 | * @param string $key [description] |
||
| 185 | * @return boolean `TRUE` iff `$params[$key]` exists and has a true value |
||
| 186 | * (`1`, `'yes'`, `'true'`, `true`, etc.), `FALSE` |
||
| 187 | * otherwise. |
||
| 188 | */ |
||
| 189 | protected function forceBoolean($params, $key) |
||
| 193 | } |
||
| 194 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.