Skip to content

Commit dc3dc5d

Browse files
committed
formatting
1 parent 05cdf3b commit dc3dc5d

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/Illuminate/Database/Eloquent/Concerns/PreventsCircularRecursion.php

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Onceable;
7+
use WeakMap;
78

89
trait PreventsCircularRecursion
910
{
@@ -14,29 +15,6 @@ trait PreventsCircularRecursion
1415
*/
1516
protected static $recursionCache;
1617

17-
/**
18-
* Get the current recursion cache being used by the model.
19-
*
20-
* @return \WeakMap
21-
*/
22-
protected static function getRecursionCache()
23-
{
24-
return static::$recursionCache ??= new \WeakMap();
25-
}
26-
27-
/**
28-
* Get the current stack of methods being called recursively.
29-
*
30-
* @param object $object
31-
* @return array
32-
*/
33-
protected static function getRecursiveCallStack($object): array
34-
{
35-
return static::getRecursionCache()->offsetExists($object)
36-
? static::getRecursionCache()->offsetGet($object)
37-
: [];
38-
}
39-
4018
/**
4119
* Prevent a method from being called multiple times on the same object within the same call stack.
4220
*
@@ -51,6 +29,7 @@ protected function withoutRecursion($callback, $default = null)
5129
$onceable = Onceable::tryFromTrace($trace, $callback);
5230

5331
$object = $onceable->object ?? $this;
32+
5433
$stack = static::getRecursiveCallStack($object);
5534

5635
if (array_key_exists($onceable->hash, $stack)) {
@@ -59,6 +38,7 @@ protected function withoutRecursion($callback, $default = null)
5938

6039
try {
6140
$stack[$onceable->hash] = is_callable($default) ? call_user_func($default) : $default;
41+
6242
static::getRecursionCache()->offsetSet($object, $stack);
6343

6444
return call_user_func($onceable->callable);
@@ -70,4 +50,27 @@ protected function withoutRecursion($callback, $default = null)
7050
}
7151
}
7252
}
53+
54+
/**
55+
* Get the current stack of methods being called recursively.
56+
*
57+
* @param object $object
58+
* @return array
59+
*/
60+
protected static function getRecursiveCallStack($object): array
61+
{
62+
return static::getRecursionCache()->offsetExists($object)
63+
? static::getRecursionCache()->offsetGet($object)
64+
: [];
65+
}
66+
67+
/**
68+
* Get the current recursion cache being used by the model.
69+
*
70+
* @return \WeakMap
71+
*/
72+
protected static function getRecursionCache()
73+
{
74+
return static::$recursionCache ??= new WeakMap();
75+
}
7376
}

0 commit comments

Comments
 (0)