Skip to content

Commit

Permalink
fix stream acl
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Jun 17, 2019
1 parent 6698428 commit a7530b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
34 changes: 26 additions & 8 deletions src/StreamAcl.php
Expand Up @@ -118,13 +118,29 @@ public function metaWriteRoles(): array

public function toArray(): array
{
return [
SystemMetadata::ACL_READ => $this->exportRoles($this->readRoles),
SystemMetadata::ACL_WRITE => $this->exportRoles($this->writeRoles),
SystemMetadata::ACL_DELETE => $this->exportRoles($this->deleteRoles),
SystemMetadata::ACL_META_READ => $this->exportRoles($this->metaReadRoles),
SystemMetadata::ACL_META_WRITE => $this->exportRoles($this->metaWriteRoles),
];
$data = [];

if (! empty($this->readRoles)) {
$data[SystemMetadata::ACL_READ] = $this->exportRoles($this->readRoles);
}

if (! empty($this->writeRoles)) {
$data[SystemMetadata::ACL_WRITE] = $this->exportRoles($this->writeRoles);
}

if (! empty($this->deleteRoles)) {
$data[SystemMetadata::ACL_DELETE] = $this->exportRoles($this->deleteRoles);
}

if (! empty($this->metaReadRoles)) {
$data[SystemMetadata::ACL_META_READ] = $this->exportRoles($this->metaReadRoles);
}

if (! empty($this->metaWriteRoles)) {
$data[SystemMetadata::ACL_META_WRITE] = $this->exportRoles($this->metaWriteRoles);
}

return $data;
}

public static function fromArray(array $data): StreamAcl
Expand All @@ -140,7 +156,9 @@ public static function fromArray(array $data): StreamAcl

private function exportRoles(?array $roles)
{
if (null === $roles) {
if (null === $roles
|| empty($roles)
) {
return null;
}

Expand Down
6 changes: 5 additions & 1 deletion src/StreamMetadata.php
Expand Up @@ -168,7 +168,11 @@ public function jsonSerialize(): object
}

if (null !== $this->acl) {
$object->{SystemMetadata::ACL} = $this->acl->toArray();
$acl = $this->acl->toArray();

if (! empty($acl)) {
$object->{SystemMetadata::ACL} = $acl;
}
}

foreach ($this->customMetadata as $key => $value) {
Expand Down

0 comments on commit a7530b1

Please sign in to comment.