-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e4c333
commit 0931fc9
Showing
50 changed files
with
3,688 additions
and
87 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Yoti\Identity\Constraint; | ||
|
||
interface Constraint | ||
{ | ||
public function getType(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Yoti\Identity\Constraint; | ||
|
||
use stdClass; | ||
use Yoti\Identity\Policy\WantedAnchor; | ||
use Yoti\Util\Validation; | ||
|
||
class PreferredSources implements \JsonSerializable | ||
{ | ||
/** | ||
* @var WantedAnchor[] | ||
*/ | ||
private array $wantedAnchors; | ||
|
||
private bool $softPreference; | ||
|
||
/** | ||
* @param WantedAnchor[] $wantedAnchors | ||
* @param bool $softPreference | ||
*/ | ||
public function __construct(array $wantedAnchors, bool $softPreference) | ||
{ | ||
Validation::isArrayOfType($wantedAnchors, [WantedAnchor::class], 'anchors'); | ||
$this->wantedAnchors = $wantedAnchors; | ||
|
||
Validation::isBoolean($softPreference, 'soft_preference'); | ||
$this->softPreference = $softPreference; | ||
} | ||
|
||
public function jsonSerialize(): stdClass | ||
{ | ||
return (object)[ | ||
'anchors' => $this->wantedAnchors, | ||
'soft_preference' => $this->softPreference, | ||
]; | ||
} | ||
|
||
/** | ||
* @return WantedAnchor[] | ||
*/ | ||
public function getWantedAnchors(): array | ||
{ | ||
return $this->wantedAnchors; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isSoftPreference(): bool | ||
{ | ||
return $this->softPreference; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Yoti\Identity\Constraint; | ||
|
||
use Yoti\Identity\Policy\WantedAnchor; | ||
use Yoti\Util\Validation; | ||
|
||
class SourceConstraint implements \JsonSerializable, Constraint | ||
{ | ||
private string $type; | ||
|
||
private PreferredSources $preferredSources; | ||
|
||
/** | ||
* @param WantedAnchor[] $wantedAnchors | ||
* @param bool $softPreference | ||
*/ | ||
public function __construct(array $wantedAnchors, bool $softPreference) | ||
{ | ||
$this->type = 'SOURCE'; | ||
|
||
Validation::isArrayOfType($wantedAnchors, [WantedAnchor::class], 'anchors'); | ||
$this->preferredSources = new PreferredSources($wantedAnchors, $softPreference); | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getPreferredSources(): PreferredSources | ||
{ | ||
return $this->preferredSources; | ||
} | ||
|
||
public function jsonSerialize(): object | ||
{ | ||
return (object)[ | ||
'type' => $this->getType(), | ||
'preferred_sources' => $this->getPreferredSources(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Yoti\Identity\Constraint; | ||
|
||
use Yoti\Identity\Policy\WantedAnchor; | ||
use Yoti\Util\Validation; | ||
|
||
class SourceConstraintBuilder | ||
{ | ||
/** | ||
* @var WantedAnchor[] | ||
*/ | ||
private array $wantedAnchors = []; | ||
|
||
private bool $softPreference = false; | ||
|
||
/** | ||
* @param WantedAnchor[] $wantedAnchors | ||
*/ | ||
public function withWantedAnchors(array $wantedAnchors): self | ||
{ | ||
Validation::isArrayOfType($wantedAnchors, [WantedAnchor::class], 'anchors'); | ||
$this->wantedAnchors = $wantedAnchors; | ||
|
||
return $this; | ||
} | ||
|
||
public function withWantedAnchor(WantedAnchor $wantedAnchor): self | ||
{ | ||
$this->wantedAnchors[] = $wantedAnchor; | ||
|
||
return $this; | ||
} | ||
|
||
public function withSoftPreference(bool $softPreference): self | ||
{ | ||
$this->softPreference = $softPreference; | ||
|
||
return $this; | ||
} | ||
|
||
public function build(): SourceConstraint | ||
{ | ||
return new SourceConstraint($this->wantedAnchors, $this->softPreference); | ||
} | ||
} |
Oops, something went wrong.