Skip to content

Commit

Permalink
Merge pull request #10 from viosys/feature/make-streams-compatible
Browse files Browse the repository at this point in the history
make streams compatible
  • Loading branch information
breaker92 authored Mar 1, 2024
2 parents 426d493 + 6a193d1 commit 0aa389b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ protected function setAttributes(array $attributes)
} elseif ($key === '@odata.etag') {
$this->etag = $attribute;
}
elseif (str_contains($key,'@odata.mediaReadLink') ) {
$attributeName = str_replace('@odata.mediaReadLink', '', $key);
$mediaReadLink = $attribute;
$this->attributes[$attributeName] = function () use ($mediaReadLink) {
try{
$response = $this->query->getSdk()->client->get($mediaReadLink);
return $response->getBody();
}
catch (\Throwable $e) {
return null;
}
};
}
}
}

Expand Down Expand Up @@ -330,6 +343,9 @@ public function doAction(string $name, array $properties = [])
public function offsetGet($offset)
{
if ($this->getEntityType()->propertyExists($offset)) {
if( $this->attributes[$offset] instanceof \Closure ) {
return $this->attributes[$offset]();
}
return $this->attributes[$offset] ?? null;
} elseif ($this->getEntityType()->relationExists($offset)) {
return $this->fetchRelation($offset);
Expand Down Expand Up @@ -428,7 +444,7 @@ public function identifiers()
{
$keys = [];
foreach ($this->getEntityType()->keys as $key) {
$keys = $this->{$key};
$keys[] = $this->{$key};
}

return $keys;
Expand Down
3 changes: 3 additions & 0 deletions src/Schema/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function convert($value)
case 'Edm.DateTimeOffset':
case 'Edm.String':
case 'Edm.Stream':
if( $value instanceof \Closure) {
return $value;
}
return (string)$value;
case 'Edm.Guid':
if ($value === '00000000-0000-0000-0000-000000000000') {
Expand Down

0 comments on commit 0aa389b

Please sign in to comment.