Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions src/Data/HasOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

namespace Statamic\Data;

use Statamic\Exceptions\RecursiveAugmentationException;
use Statamic\Facades\Blink;

trait HasOrigin
{
private $resolvingValues = false;

/**
* @var string
*/
Expand All @@ -34,33 +31,14 @@ public function keys()
->merge($computedKeys);
}

private function guardRecursiveAugmentation()
{
if ($this->resolvingValues) {
$className = get_class($this);
throw new RecursiveAugmentationException("Recursion detected while augmenting [{$className}] with ID [{$this->id}].");
}

$this->resolvingValues = true;
}

private function ungardRecursiveAugmentation()
{
$this->resolvingValues = false;
}

public function values()
{
$this->guardRecursiveAugmentation();

$originFallbackValues = method_exists($this, 'getOriginFallbackValues') ? $this->getOriginFallbackValues() : collect();

$originValues = $this->hasOrigin() ? $this->origin()->values() : collect();

$computedData = method_exists($this, 'computedData') ? $this->computedData() : [];

$this->ungardRecursiveAugmentation();

return collect()
->merge($originFallbackValues)
->merge($originValues)
Expand Down
7 changes: 0 additions & 7 deletions src/Exceptions/RecursiveAugmentationException.php

This file was deleted.

20 changes: 0 additions & 20 deletions tests/Data/Entries/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Statamic\Events\EntryDeleting;
use Statamic\Events\EntrySaved;
use Statamic\Events\EntrySaving;
use Statamic\Exceptions\RecursiveAugmentationException;
use Statamic\Facades;
use Statamic\Facades\Blink;
use Statamic\Fields\Blueprint;
Expand Down Expand Up @@ -2679,23 +2678,4 @@ public function it_clones_internal_collections()
$this->assertEquals('A', $entry->getSupplement('bar'));
$this->assertEquals('B', $clone->getSupplement('bar'));
}

#[Test]
public function it_detects_recursive_augmentation()
{
$this->expectException(RecursiveAugmentationException::class);
$this->expectExceptionMessage('Recursion detected while augmenting [Statamic\Entries\Entry] with ID [entry-id]');

\Statamic\Facades\Collection::computed('test', 'the_value', function ($entry) {
// Trigger recursion that will bypass without computed values.
return $entry->routeData();
});

$entry = EntryFactory::id('entry-id')
->collection('test')
->slug('entry-slug')
->create();

$entry->values();
}
}