Skip to content

Commit 93c4dbe

Browse files
committed
Added "throw exception on double initialization" option to kernel
1 parent 54077ec commit 93c4dbe

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/CodeTransformerKernel.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ public function __construct() {}
8080
*/
8181
protected bool $debug = false;
8282

83+
/**
84+
* Throw an exception if the kernel is initialized twice.
85+
* <br><b>Default:</b> {@link false}<br>
86+
*
87+
* If {@link false}, any subsequent call to {@link init()} will be
88+
* ignored.
89+
*
90+
* @var bool
91+
*/
92+
protected bool $throwExceptionOnDoubleInitialization = false;
93+
8394
// endregion
8495

8596
/**
@@ -115,7 +126,12 @@ public static function init(): void
115126
static::ensureNotKernelNamespace();
116127

117128
$instance = static::getInstance();
118-
$instance->ensureNotInitialized();
129+
130+
if ($instance->throwExceptionOnDoubleInitialization) {
131+
$instance->ensureNotInitialized();
132+
} elseif ($instance->initialized) {
133+
return;
134+
}
119135

120136
// Initialize the services
121137
$instance->preInit();

0 commit comments

Comments
 (0)