|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Surfnet\StepupMiddlewareClient\Configuration\Dto; |
|
4
|
|
|
|
|
5
|
|
|
use Assert; |
|
6
|
|
|
use Surfnet\StepupMiddlewareClient\Dto\HttpQuery; |
|
7
|
|
|
|
|
8
|
|
|
class RaLocationSearchQuery implements HttpQuery |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
private $institution; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string|null |
|
17
|
|
|
*/ |
|
18
|
|
|
private $orderBy = 'name'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string|null |
|
22
|
|
|
*/ |
|
23
|
|
|
private $orderDirection = 'asc'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $institution |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($institution) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertNonEmptyString($institution, 'institution'); |
|
31
|
|
|
|
|
32
|
|
|
$this->institution = $institution; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getInstitution() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->institution; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $orderBy |
|
45
|
|
|
* @return $this |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setOrderBy($orderBy) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertNonEmptyString($orderBy, 'orderBy'); |
|
50
|
|
|
|
|
51
|
|
|
$this->orderBy = $orderBy; |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $orderDirection |
|
58
|
|
|
* @return $this |
|
59
|
|
|
*/ |
|
60
|
|
|
public function setOrderDirection($orderDirection) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->assertNonEmptyString($orderDirection, 'orderDirection'); |
|
63
|
|
|
Assert\that($orderDirection)->choice( |
|
64
|
|
|
['asc', 'desc', '', null], |
|
65
|
|
|
"Invalid order direction, must be one of 'asc', 'desc'" |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
$this->orderDirection = $orderDirection; |
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function assertNonEmptyString($value, $name) |
|
74
|
|
|
{ |
|
75
|
|
|
$message = sprintf( |
|
76
|
|
|
'"%s" must be a non-empty string, "%s" given', |
|
77
|
|
|
$name, |
|
78
|
|
|
(is_object($value) ? get_class($value) : gettype($value)) |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
Assert\that($value)->string($message)->notEmpty($message); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function toHttpQuery() |
|
85
|
|
|
{ |
|
86
|
|
|
return '?institution=' . urlencode($this->institution) |
|
87
|
|
|
. '&orderBy=' . urlencode($this->orderBy) |
|
88
|
|
|
. '&orderDirection' . urlencode($this->orderDirection); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|