From 6f7610c7829ba95f36aed7cef953735ce29873c7 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Thu, 14 Mar 2024 23:29:41 +0300 Subject: [PATCH] Add internal scope object --- .../administrator/src/ValueObject/Scope.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 com_oauthserver/administrator/src/ValueObject/Scope.php diff --git a/com_oauthserver/administrator/src/ValueObject/Scope.php b/com_oauthserver/administrator/src/ValueObject/Scope.php new file mode 100644 index 0000000..93304b7 --- /dev/null +++ b/com_oauthserver/administrator/src/ValueObject/Scope.php @@ -0,0 +1,82 @@ + + * @license MIT; see LICENSE.txt + **/ + +namespace Webmasterskaya\Component\OauthServer\Administrator\ValueObject; + +final class Scope +{ + private string $identifier; + + private ?string $name; + + private ?string $description; + + private ?string $parent; + + /** + * @param string $identifier + * @param string|null $name + * @param string|null $description + * @param string|null $parent + * + * @since version + */ + public function __construct(string $identifier, ?string $name = null, ?string $description = null, ?string $parent = null) + { + $this->identifier = $this->cleanUp($identifier); + $this->name = $name; + $this->description = $description; + $this->parent = $this->cleanUp($parent); + } + + public function getIdentifier(): string + { + return $this->identifier; + } + + public function setIdentifier(string $identifier): void + { + $this->identifier = $this->cleanUp($identifier); + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): void + { + $this->name = $name; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(string $description): void + { + $this->description = $description; + } + + public function getParent(): ?string + { + return $this->parent; + } + + public function setParent(string $parent): void + { + $this->parent = $this->cleanUp($parent); + } + + private function cleanUp(?string $string): ?string + { + return is_null($string) ? null : preg_replace('/[^A-Z0-9_-]/i', '', $string); + } +}