Skip to content

Commit

Permalink
Added convenience methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alsbury committed Nov 9, 2022
1 parent bc496c9 commit 1e879fd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Model/CheckPermissionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ public function setPermissionship(string $permissionship): self
$this->permissionship = $permissionship;
return $this;
}

public function __toString(): string
{
return $this->getPermissionship();
}


}
4 changes: 2 additions & 2 deletions src/Model/Consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Model/ObjectReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,5 +50,8 @@ public function __toString(): string
return $this->getObjectType() . ':' . $this->getObjectId();
}


public function toArray()
{
return [$this->getObjectType(), $this->getObjectId()];
}
}
2 changes: 1 addition & 1 deletion src/Model/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
2 changes: 1 addition & 1 deletion src/Model/SubjectFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
13 changes: 13 additions & 0 deletions src/Model/SubjectReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 1e879fd

Please sign in to comment.