Skip to content

Commit

Permalink
feat!: Changed WebResponseDataTransformerInterface transform signatur…
Browse files Browse the repository at this point in the history
…e to allow passing an existing WebResponseInterface
  • Loading branch information
roadiz-ci committed Nov 25, 2024
1 parent 38c84fb commit bcffe3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ interface WebResponseDataTransformerInterface
* @template T of PersistableInterface
*
* @param T $object
* @param WebResponseInterface|null $output Pass an existing WebResponseInterface instance to avoid creating a new one.
*
* @return WebResponseInterface<T>|null
*/
public function transform(PersistableInterface $object, string $to, array $context = []): ?WebResponseInterface;
public function transform(
PersistableInterface $object,
string $to,
array $context = [],
?WebResponseInterface $output = null,
): ?WebResponseInterface;

public function createWebResponse(): WebResponseInterface;
}
4 changes: 2 additions & 2 deletions src/Api/DataTransformer/WebResponseOutputDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public function createWebResponse(): WebResponseInterface
return new ($this->webResponseClass)();
}

public function transform(PersistableInterface $object, string $to, array $context = []): ?WebResponseInterface
public function transform(PersistableInterface $object, string $to, array $context = [], ?WebResponseInterface $output = null): ?WebResponseInterface
{
$output = $this->createWebResponse();
$output = $output ?? $this->createWebResponse();
$output->setItem($object);
if ($object instanceof NodesSources) {
if ($output instanceof RealmsAwareWebResponseInterface) {
Expand Down

0 comments on commit bcffe3e

Please sign in to comment.