Skip to content

Commit

Permalink
Wrapping fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jan 8, 2024
1 parent 49a4c6e commit b3c899f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Resolvers/TransformedDataCollectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function execute(
: new Wrap(WrapType::UseGlobal);

$nestedContext = $context->wrapExecutionType->shouldExecute()
? $context->setWrapExecutionType(WrapExecutionType::TemporarilyDisabled)
? (clone $context)->setWrapExecutionType(WrapExecutionType::TemporarilyDisabled)
: $context;

if ($items instanceof DataCollection) {
Expand Down
13 changes: 12 additions & 1 deletion src/Support/Partials/ResolvedPartialsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
namespace Spatie\LaravelData\Support\Partials;

use SplObjectStorage;
use Stringable;

/**
* @extends SplObjectStorage<ResolvedPartial>
*/
class ResolvedPartialsCollection extends SplObjectStorage
class ResolvedPartialsCollection extends SplObjectStorage implements Stringable
{

public function __toString(): string
{
$output = "- excludedPartials:".PHP_EOL;

foreach ($this as $excludedPartial) {
$output .= " - {$excludedPartial}".PHP_EOL;
}

return $output;
}
}
36 changes: 8 additions & 28 deletions src/Support/Transformation/TransformationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@ public function __construct(

public function setWrapExecutionType(WrapExecutionType $wrapExecutionType): self
{
// Todo: remove and run directly on object

return new self(
$this->transformValues,
$this->mapPropertyNames,
$wrapExecutionType,
$this->includedPartials,
$this->excludedPartials,
$this->onlyPartials,
$this->exceptPartials,
);
$this->wrapExecutionType = $wrapExecutionType;

return $this;
}

public function addIncludedResolvedPartial(ResolvedPartial ...$resolvedPartials): void
Expand Down Expand Up @@ -166,7 +158,7 @@ public function __clone(): void

public function __toString(): string
{
$output = 'Transformation Context '.spl_object_id($this).PHP_EOL;
$output = 'Transformation Context ('.spl_object_id($this).')'.PHP_EOL;

$output .= "- wrapExecutionType: {$this->wrapExecutionType->name}".PHP_EOL;

Expand All @@ -179,31 +171,19 @@ public function __toString(): string
}

if ($this->includedPartials !== null && $this->includedPartials->count() > 0) {
$output .= "- includedPartials:".PHP_EOL;
foreach ($this->includedPartials as $includedPartial) {
$output .= " - {$includedPartial}".PHP_EOL;
}
$output .= $this->includedPartials;
}

if ($this->excludedPartials !== null && $this->excludedPartials->count() > 0) {
$output .= "- excludedPartials:".PHP_EOL;
foreach ($this->excludedPartials as $excludedPartial) {
$output .= " - {$excludedPartial}".PHP_EOL;
}
$output .= $this->excludedPartials;
}

if ($this->onlyPartials !== null && $this->onlyPartials->count() > 0) {
$output .= "- onlyPartials:".PHP_EOL;
foreach ($this->onlyPartials as $onlyPartial) {
$output .= " - {$onlyPartial}".PHP_EOL;
}
$output .= $this->onlyPartials;
}

if ($this->exceptPartials !== null && $this->exceptPartials->count() > 0) {
$output .= "- exceptPartials:".PHP_EOL;
foreach ($this->exceptPartials as $exceptPartial) {
$output .= " - {$exceptPartial}".PHP_EOL;
}
$output .= $this->exceptPartials;
}

return $output;
Expand Down
2 changes: 1 addition & 1 deletion tests/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ public static function fromData(Data $data)
->and($dataClass::from(new EnumData(DummyBackedEnum::FOO)))->toEqual(new $dataClass('data', '{"enum":"foo"}'));
});

it('can wrap data objects', function () {
it('can wrap data objects by method call', function () {
expect(
SimpleData::from('Hello World')
->wrap('wrap')
Expand Down

0 comments on commit b3c899f

Please sign in to comment.