|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XHGui\Options; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
6
|
|
|
use XHGui\Searcher\SearcherInterface; |
|
7
|
|
|
|
|
8
|
|
|
class SearchOptions extends OptionsConfigurator |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Options for SearchInterface::getAll |
|
12
|
|
|
* |
|
13
|
|
|
* - sort: an array of search criteria (TODO meta.SERVER.REQUEST_TIME => -1 ????) |
|
14
|
|
|
* - direction: an string, either 'desc' or 'asc' |
|
15
|
|
|
* - page: an integer, the page to display (e.g. 3) |
|
16
|
|
|
* - perPage: an integer, how many profiles to display per page (e.g. 25) |
|
17
|
|
|
* - conditions: an array of criteria to match |
|
18
|
|
|
* - projection: an array or bool |
|
19
|
|
|
*/ |
|
20
|
|
|
protected function configureOptions(OptionsResolver $resolver) |
|
21
|
|
|
{ |
|
22
|
|
|
$resolver->setDefaults([ |
|
23
|
|
|
'sort' => null, |
|
24
|
|
|
'direction' => SearcherInterface::DEFAULT_DIRECTION, |
|
25
|
|
|
'page' => SearcherInterface::DEFAULT_PAGE, |
|
26
|
|
|
'perPage' => null, |
|
27
|
|
|
'conditions' => [], |
|
28
|
|
|
'projection' => null, |
|
29
|
|
|
]); |
|
30
|
|
|
$resolver->setRequired(['sort', 'direction', 'page', 'perPage']); |
|
31
|
|
|
$resolver->setAllowedTypes('sort', 'string'); |
|
32
|
|
|
$resolver->setAllowedTypes('page', 'int'); |
|
33
|
|
|
$resolver->setAllowedTypes('projection', ['null', 'bool', 'array']); |
|
34
|
|
|
$resolver->setAllowedTypes('conditions', 'array'); |
|
35
|
|
|
$resolver->setAllowedValues('direction', ['asc', 'desc']); |
|
36
|
|
|
$resolver->setAllowedValues('sort', ['time', 'wt', 'cpu', 'mu', 'pmu']); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|