Skip to content

Commit ef0f206

Browse files
committed
include the file only if it makes sense to prevent "class name already in use" error
1 parent 2b56326 commit ef0f206

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Compiler/Compiler.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public function compile(
4141

4242
$fqcn = (string) ($class = ($context->getClass() ?? new ClassReferenceMetadata($className, $namespace)));
4343

44-
if ($context->getFilePath() !== null && file_exists($context->getFilePath())) {
45-
include_once $context->getFilePath();
46-
}
47-
4844
$tree = $this->strategy->buildTree(
4945
$context->getPropertyPath(),
5046
$class,
@@ -54,7 +50,9 @@ public function compile(
5450
$prettyPrinter = new PrettyPrinter\Standard();
5551
if ($context->getFilePath() !== null && is_writable(dirname($context->getFilePath()))) {
5652
file_put_contents($context->getFilePath(), $prettyPrinter->prettyPrintFile($tree));
57-
include_once $context->getFilePath();
53+
if (!class_exists($fqcn)) {
54+
include_once $context->getFilePath();
55+
}
5856
} else {
5957
include_once 'data://text/plain;base64,' . base64_encode($prettyPrinter->prettyPrintFile($tree));
6058
}

0 commit comments

Comments
 (0)