From 1e879fdfec8dc1cc11067ffb8ab2fd995c6c594b Mon Sep 17 00:00:00 2001 From: alsbury Date: Wed, 9 Nov 2022 16:51:39 -0600 Subject: [PATCH] Added convenience methods --- src/Model/CheckPermissionResponse.php | 7 +++++++ src/Model/Consistency.php | 4 ++-- src/Model/ObjectReference.php | 10 +++++++++- src/Model/Relationship.php | 2 +- src/Model/SubjectFilter.php | 2 +- src/Model/SubjectReference.php | 13 +++++++++++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Model/CheckPermissionResponse.php b/src/Model/CheckPermissionResponse.php index 6b04623..9345be5 100644 --- a/src/Model/CheckPermissionResponse.php +++ b/src/Model/CheckPermissionResponse.php @@ -35,4 +35,11 @@ public function setPermissionship(string $permissionship): self $this->permissionship = $permissionship; return $this; } + + public function __toString(): string + { + return $this->getPermissionship(); + } + + } \ No newline at end of file diff --git a/src/Model/Consistency.php b/src/Model/Consistency.php index 3f083c2..4c52e0d 100644 --- a/src/Model/Consistency.php +++ b/src/Model/Consistency.php @@ -48,12 +48,12 @@ public function __construct( $this->fullyConsistent = $fullyConsistent; } - public static function minimizeLatency() + public static function minimizeLatency(): Consistency { return new self(null, null, true); } - public static function fullyConsistent() + public static function fullyConsistent(): Consistency { return new self(null, null, null, true); } diff --git a/src/Model/ObjectReference.php b/src/Model/ObjectReference.php index d7ad974..a5c67f8 100644 --- a/src/Model/ObjectReference.php +++ b/src/Model/ObjectReference.php @@ -18,6 +18,11 @@ public static function create(string $objectType, string $objectId): ObjectRefer return new self($objectType, $objectId); } + public static function createFromArray(array $data): self + { + return new self($data[0], $data[1]); + } + public function getObjectType(): string { return $this->objectType; @@ -45,5 +50,8 @@ public function __toString(): string return $this->getObjectType() . ':' . $this->getObjectId(); } - + public function toArray() + { + return [$this->getObjectType(), $this->getObjectId()]; + } } \ No newline at end of file diff --git a/src/Model/Relationship.php b/src/Model/Relationship.php index dc121ac..7e160e9 100644 --- a/src/Model/Relationship.php +++ b/src/Model/Relationship.php @@ -63,7 +63,7 @@ public function setSubject(?SubjectReference $subject): self public function __toString(): string { - return $this->resource . '@' . $this->subject; + return $this->resource . '#' . $this->relation . '@' . $this->subject; } } \ No newline at end of file diff --git a/src/Model/SubjectFilter.php b/src/Model/SubjectFilter.php index bb41a8d..6ec9926 100644 --- a/src/Model/SubjectFilter.php +++ b/src/Model/SubjectFilter.php @@ -55,7 +55,7 @@ public static function fromSubject(\Lifestyle\Integration\SpiceDB\Service\Model\ public function __toString(): string { - return self::class; + return SubjectReference::create($this->subjectType, $this->optionalSubjectId, $this->optionalRelation); } diff --git a/src/Model/SubjectReference.php b/src/Model/SubjectReference.php index 64ae3f7..8885f69 100644 --- a/src/Model/SubjectReference.php +++ b/src/Model/SubjectReference.php @@ -29,6 +29,11 @@ public static function create(string $objectType, string $objectId, string $opti return new self(new ObjectReference($objectType, $objectId), $optionalRelation); } + public static function createFromArray(array $data) + { + return new self(new ObjectReference($data[0], $data[1]), $data[2] ?? null); + } + public function getObject(): ObjectReference { return $this->object; @@ -56,5 +61,13 @@ public function __toString(): string return $this->getObject() . ($this->getOptionalRelation() ? '#'. $this->getOptionalRelation() : ''); } + public function toArray() + { + $arr = [$this->getObject()->getObjectType(), $this->getObject()->getObjectId()]; + if ($this->getOptionalRelation()) { + $arr[2] = $this->getOptionalRelation(); + } + return $arr; + } } \ No newline at end of file