@@ -20,6 +20,8 @@ class Loop
20
20
21
21
protected string $ context = '' ;
22
22
23
+ protected bool $ hasBeenResolved = false ;
24
+
23
25
public function __construct ()
24
26
{
25
27
$ this ->tools = new ToolCollection ;
@@ -36,7 +38,9 @@ public function context(string $context): static
36
38
37
39
public function tool (Tool $ tool ): static
38
40
{
39
- $ this ->tools ->push ($ tool );
41
+ if (! $ this ->hasBeenResolved ) {
42
+ $ this ->tools ->push ($ tool );
43
+ }
40
44
41
45
$ this ->storeRegistration (function (Loop $ loop ) use ($ tool ) {
42
46
$ loop ->tools ->push ($ tool );
@@ -47,8 +51,10 @@ public function tool(Tool $tool): static
47
51
48
52
public function toolkit (Toolkit $ toolkit ): static
49
53
{
50
- foreach ($ toolkit ->getTools () as $ tool ) {
51
- $ this ->tools ->push ($ tool );
54
+ if (! $ this ->hasBeenResolved ) {
55
+ foreach ($ toolkit ->getTools () as $ tool ) {
56
+ $ this ->tools ->push ($ tool );
57
+ }
52
58
}
53
59
54
60
$ this ->storeRegistration (function (Loop $ loop ) use ($ toolkit ) {
@@ -132,4 +138,14 @@ protected function storeRegistration(callable $callback): void
132
138
$ registrations [] = $ callback ;
133
139
app ()->instance ('loop.registrations ' , $ registrations );
134
140
}
141
+
142
+ public function markAsResolved (): void
143
+ {
144
+ $ this ->hasBeenResolved = true ;
145
+ }
146
+
147
+ public function hasBeenResolved (): bool
148
+ {
149
+ return $ this ->hasBeenResolved ;
150
+ }
135
151
}
0 commit comments