| @@ 24-127 (lines=104) @@ | ||
| 21 | use Assert; |
|
| 22 | use Surfnet\StepupMiddlewareClient\Dto\HttpQuery; |
|
| 23 | ||
| 24 | class IdentitySearchQuery implements HttpQuery |
|
| 25 | { |
|
| 26 | /** |
|
| 27 | * @var string |
|
| 28 | */ |
|
| 29 | private $nameId; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @var string |
|
| 33 | */ |
|
| 34 | private $institution; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @var string |
|
| 38 | */ |
|
| 39 | private $email; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @var string |
|
| 43 | */ |
|
| 44 | private $commonName; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param string $institution |
|
| 48 | */ |
|
| 49 | public function __construct($institution) |
|
| 50 | { |
|
| 51 | $this->assertNonEmptyString($institution, 'institution'); |
|
| 52 | ||
| 53 | $this->institution = $institution; |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * @param string $commonName |
|
| 58 | * @return IdentitySearchQuery |
|
| 59 | */ |
|
| 60 | public function setCommonName($commonName) |
|
| 61 | { |
|
| 62 | $this->assertNonEmptyString($commonName, 'commonName'); |
|
| 63 | ||
| 64 | $this->commonName = $commonName; |
|
| 65 | ||
| 66 | return $this; |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @param string $email |
|
| 71 | * @return IdentitySearchQuery |
|
| 72 | */ |
|
| 73 | public function setEmail($email) |
|
| 74 | { |
|
| 75 | $this->assertNonEmptyString($email, 'email'); |
|
| 76 | ||
| 77 | $this->email = $email; |
|
| 78 | ||
| 79 | return $this; |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * @param string $nameId |
|
| 84 | * @return IdentitySearchQuery |
|
| 85 | */ |
|
| 86 | public function setNameId($nameId) |
|
| 87 | { |
|
| 88 | $this->assertNonEmptyString($nameId, 'nameId'); |
|
| 89 | ||
| 90 | $this->nameId = $nameId; |
|
| 91 | ||
| 92 | return $this; |
|
| 93 | } |
|
| 94 | ||
| 95 | private function assertNonEmptyString($value, $name) |
|
| 96 | { |
|
| 97 | $message = sprintf( |
|
| 98 | '"%s" must be a non-empty string, "%s" given', |
|
| 99 | $name, |
|
| 100 | (is_object($value) ? get_class($value) : gettype($value)) |
|
| 101 | ); |
|
| 102 | ||
| 103 | Assert\that($value)->string($message)->notEmpty($message); |
|
| 104 | } |
|
| 105 | ||
| 106 | /** |
|
| 107 | * @return string |
|
| 108 | */ |
|
| 109 | public function toHttpQuery() |
|
| 110 | { |
|
| 111 | $fields = ['institution' => $this->institution]; |
|
| 112 | ||
| 113 | if ($this->commonName) { |
|
| 114 | $fields['commonName'] = $this->commonName; |
|
| 115 | } |
|
| 116 | ||
| 117 | if ($this->email) { |
|
| 118 | $fields['email'] = $this->email; |
|
| 119 | } |
|
| 120 | ||
| 121 | if ($this->nameId) { |
|
| 122 | $fields['NameID'] = $this->nameId; |
|
| 123 | } |
|
| 124 | ||
| 125 | return '?' . http_build_query($fields); |
|
| 126 | } |
|
| 127 | } |
|
| 128 | ||
| @@ 24-128 (lines=105) @@ | ||
| 21 | use Assert; |
|
| 22 | use Surfnet\StepupMiddlewareClient\Dto\HttpQuery; |
|
| 23 | ||
| 24 | class VerifiedSecondFactorSearchQuery implements HttpQuery |
|
| 25 | { |
|
| 26 | /** |
|
| 27 | * @var string |
|
| 28 | */ |
|
| 29 | private $identityId; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @var string |
|
| 33 | */ |
|
| 34 | private $secondFactorId; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @var string |
|
| 38 | */ |
|
| 39 | private $registrationCode; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @var string |
|
| 43 | */ |
|
| 44 | private $actorInstitution; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param string $identityId |
|
| 48 | * @return self |
|
| 49 | */ |
|
| 50 | public function setIdentityId($identityId) |
|
| 51 | { |
|
| 52 | $this->assertNonEmptyString($identityId, 'identityId'); |
|
| 53 | ||
| 54 | $this->identityId = $identityId; |
|
| 55 | ||
| 56 | return $this; |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * @param string $secondFactorId |
|
| 61 | * @return self |
|
| 62 | */ |
|
| 63 | public function setSecondFactorId($secondFactorId) |
|
| 64 | { |
|
| 65 | $this->assertNonEmptyString($secondFactorId, 'secondFactorId'); |
|
| 66 | ||
| 67 | $this->secondFactorId = $secondFactorId; |
|
| 68 | ||
| 69 | return $this; |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * @param string $registrationCode |
|
| 74 | * @return self |
|
| 75 | */ |
|
| 76 | public function setRegistrationCode($registrationCode) |
|
| 77 | { |
|
| 78 | $this->assertNonEmptyString($registrationCode, 'registrationCode'); |
|
| 79 | ||
| 80 | $this->registrationCode = $registrationCode; |
|
| 81 | ||
| 82 | return $this; |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * @param string $actorInstitution |
|
| 87 | */ |
|
| 88 | public function setActorInstitution($actorInstitution) |
|
| 89 | { |
|
| 90 | $this->assertNonEmptyString($actorInstitution, 'actorInstitution'); |
|
| 91 | ||
| 92 | $this->actorInstitution = $actorInstitution; |
|
| 93 | ||
| 94 | return $this; |
|
| 95 | } |
|
| 96 | ||
| 97 | private function assertNonEmptyString($value, $name) |
|
| 98 | { |
|
| 99 | $message = sprintf( |
|
| 100 | '"%s" must be a non-empty string, "%s" given', |
|
| 101 | $name, |
|
| 102 | (is_object($value) ? get_class($value) : gettype($value)) |
|
| 103 | ); |
|
| 104 | ||
| 105 | Assert\that($value)->string($message)->notEmpty($message); |
|
| 106 | } |
|
| 107 | ||
| 108 | public function toHttpQuery() |
|
| 109 | { |
|
| 110 | $fields = []; |
|
| 111 | ||
| 112 | $fields['actorInstitution'] = $this->actorInstitution; |
|
| 113 | ||
| 114 | if ($this->identityId) { |
|
| 115 | $fields['identityId'] = $this->identityId; |
|
| 116 | } |
|
| 117 | ||
| 118 | if ($this->secondFactorId) { |
|
| 119 | $fields['secondFactorId'] = $this->secondFactorId; |
|
| 120 | } |
|
| 121 | ||
| 122 | if ($this->registrationCode) { |
|
| 123 | $fields['registrationCode'] = $this->registrationCode; |
|
| 124 | } |
|
| 125 | ||
| 126 | return '?' . http_build_query($fields); |
|
| 127 | } |
|
| 128 | } |
|
| 129 | ||