diff --git a/src/AbstractCompiledContainer.php b/src/AbstractCompiledContainer.php index 808ad7e..8cf0d82 100644 --- a/src/AbstractCompiledContainer.php +++ b/src/AbstractCompiledContainer.php @@ -7,6 +7,8 @@ use Closure; use Psr\Container\ContainerInterface; +use function property_exists; + abstract class AbstractCompiledContainer implements ContainerInterface { /** @var array */ @@ -18,7 +20,9 @@ protected function setClassProperties(object $object, array $properties): object Closure::bind( static function () use ($object, $properties): void { foreach ($properties as $name => $value) { - $object->$name = $value; + if (property_exists($object, $name)) { + $object->$name = $value; + } } }, null, diff --git a/src/Container/Definition/ClassDefinition.php b/src/Container/Definition/ClassDefinition.php index ba91124..a08e3d9 100644 --- a/src/Container/Definition/ClassDefinition.php +++ b/src/Container/Definition/ClassDefinition.php @@ -247,7 +247,7 @@ public function compile( $code = ""; if ($inline === false) { - $code .= "${indent}return "; + $code .= "{$indent}return "; } if ($this->isSingletonCheckEliminable($parentId) === false) { @@ -256,7 +256,7 @@ public function compile( if ($hasProperties) { $code .= "\$this->setClassProperties(\n"; - $code .= "${indent}${tab}"; + $code .= "{$indent}{$tab}"; } $code .= "new \\" . $this->getClassName() . "("; @@ -271,40 +271,40 @@ public function compile( if (array_key_exists("class", $constructorArgument)) { $definition = $compilation->getDefinition($constructorArgument["class"]); - $code .= "\n${constructorIndent}${tab}" . $this->compileEntryReference( + $code .= "\n{$constructorIndent}{$tab}" . $this->compileEntryReference( $definition, $compilation, $constructorIndentationLevel + 1, $preloadedClasses ) . ","; } elseif (array_key_exists("value", $constructorArgument)) { - $code .= "\n${constructorIndent}${tab}" . $this->serializeValue($constructorArgument["value"]) . ","; + $code .= "\n{$constructorIndent}{$tab}" . $this->serializeValue($constructorArgument["value"]) . ","; } } if ($hasConstructorArguments) { - $code .= "\n${constructorIndent})"; + $code .= "\n{$constructorIndent})"; } if ($hasProperties) { $code .= ",\n"; - $code .= "${indent}${tab}[\n"; + $code .= "{$indent}{$tab}[\n"; foreach ($this->properties as $propertyName => $property) { if (array_key_exists("class", $property)) { $definition = $compilation->getDefinition($property["class"]); - $code .= "${indent}${tab}${tab}'$propertyName' => " . $this->compileEntryReference( + $code .= "{$indent}{$tab}{$tab}'$propertyName' => " . $this->compileEntryReference( $definition, $compilation, $indentationLevel + 2, $preloadedClasses ) . ",\n"; } elseif (array_key_exists("value", $property)) { - $code .= "${indent}${tab}${tab}'$propertyName' => " . $this->serializeValue($property["value"]) . ",\n"; + $code .= "{$indent}{$tab}{$tab}'$propertyName' => " . $this->serializeValue($property["value"]) . ",\n"; } } - $code .= "${indent}${tab}]\n"; - $code .= "${indent})"; + $code .= "{$indent}{$tab}]\n"; + $code .= "{$indent})"; } if ($inline === false) { diff --git a/src/Container/Definition/ReferenceDefinition.php b/src/Container/Definition/ReferenceDefinition.php index cf5ebfd..d8531a9 100644 --- a/src/Container/Definition/ReferenceDefinition.php +++ b/src/Container/Definition/ReferenceDefinition.php @@ -131,7 +131,7 @@ public function compile( $code = ""; if ($inline === false) { - $code .= "${indent}return "; + $code .= "{$indent}return "; } if ($this->isSingletonCheckEliminable($parentId) === false) { diff --git a/src/Container/Definition/SelfDefinition.php b/src/Container/Definition/SelfDefinition.php index c9e8bd8..ace0056 100644 --- a/src/Container/Definition/SelfDefinition.php +++ b/src/Container/Definition/SelfDefinition.php @@ -67,6 +67,6 @@ public function compile( return "\$this"; } - return "${indent}return \$this;\n"; + return "{$indent}return \$this;\n"; } } diff --git a/tests/Double/StubPrototypeDefinition.php b/tests/Double/StubPrototypeDefinition.php index f1473d4..87d508a 100644 --- a/tests/Double/StubPrototypeDefinition.php +++ b/tests/Double/StubPrototypeDefinition.php @@ -25,6 +25,6 @@ public function compile( ): string { $indent = $this->indent($indentationLevel); - return "${indent}// This is a dummy definition.\n"; + return "{$indent}// This is a dummy definition.\n"; } } diff --git a/tests/Double/StubSingletonDefinition.php b/tests/Double/StubSingletonDefinition.php index fb488fa..315994e 100644 --- a/tests/Double/StubSingletonDefinition.php +++ b/tests/Double/StubSingletonDefinition.php @@ -38,6 +38,6 @@ public function compile( ): string { $indent = $this->indent($indentationLevel); - return "${indent}// This is a dummy definition.\n"; + return "{$indent}// This is a dummy definition.\n"; } }