Skip to content

Commit

Permalink
Pass indentation level to custom object exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 31, 2024
1 parent af726e4 commit a05140e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private function exportObject(object $value, RecursionContext $processed, string
$processed->add($value);

if ($this->objectExporter !== null && $this->objectExporter->handles($value)) {
$buffer = $this->objectExporter->export($value, $this);
$buffer = $this->objectExporter->export($value, $this, $indentation);
} else {
$buffer = $this->defaultObjectExport($value, $processed, $whitespace, $indentation);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ObjectExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface ObjectExporter
{
public function handles(object $object): bool;

public function export(object $object, Exporter $exporter): string;
public function export(object $object, Exporter $exporter, int $indentation): string;
}
4 changes: 2 additions & 2 deletions src/ObjectExporterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function handles(object $object): bool
/**
* @throws ObjectNotSupportedException
*/
public function export(object $object, Exporter $exporter): string
public function export(object $object, Exporter $exporter, int $indentation): string
{
foreach ($this->exporter as $objectExporter) {
if ($objectExporter->handles($object)) {
return $objectExporter->export($object, $exporter);
return $objectExporter->export($object, $exporter, $indentation);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ObjectExporterChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testDelegatesExportingToFirstExporterThatHandlesAnObject(): void

$chain = new ObjectExporterChain([$firstExporter, $secondExporter]);

$this->assertSame('string', $chain->export(new stdClass, new Exporter));
$this->assertSame('string', $chain->export(new stdClass, new Exporter, 0));
}

public function testCannotExportObjectWhenNoExporterHandlesIt(): void
Expand All @@ -59,6 +59,6 @@ public function testCannotExportObjectWhenNoExporterHandlesIt(): void

$this->expectException(ObjectNotSupportedException::class);

$this->assertSame('string', $chain->export(new stdClass, new Exporter));
$this->assertSame('string', $chain->export(new stdClass, new Exporter, 0));
}
}

0 comments on commit a05140e

Please sign in to comment.