Skip to content

Commit

Permalink
Allow for custom hydrator when embedding resources
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Dec 8, 2021
1 parent b29c926 commit 9b4f910
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ public function addEmbeddedResource(string $ref, Resource $resource): self
return $this;
}

public function addEmbeddedResources(string $ref, Collection $collection): self
public function addEmbeddedResources(string $ref, Collection $collection, string $hydrator = null): self
{
if (! isset($this->embedded[$ref])) {
$this->embedded[$ref] = [];
}

$collection->each(function ($item) use ($ref): void {
$collection->each(function ($item) use ($ref, $hydrator): void {
if ($item instanceof Resource) {
$this->embedded[$ref][] = $item;
} elseif ($hydrator) {
$this->embedded[$ref][] = $this->hydratorManager->extract($item, $hydrator);
} elseif ($this->hydratorManager->canExtract($item)) {
$this->embedded[$ref][] = $this->hydratorManager->extract($item);
} else {
Expand Down

0 comments on commit 9b4f910

Please sign in to comment.