diff --git a/src/ContainerBuilder.php b/src/ContainerBuilder.php index e3ac1cf..31ae740 100644 --- a/src/ContainerBuilder.php +++ b/src/ContainerBuilder.php @@ -37,6 +37,13 @@ class ContainerBuilder */ protected ?string $containerNamespace = null; + /** + * Should we override the debug function in the generated container + * So that when the container is var_dump't we do not end in an + * infinite recrusion? + */ + protected bool $overrideDebugInfo = true; + /** * An array of paramters to be builded directly * as propterty. @@ -64,7 +71,7 @@ class ContainerBuilder * * @var array */ - protected array$shared = []; + protected array $shared = []; /** * An array of converted service names @@ -114,6 +121,18 @@ public function setContainerName(string $containerName) } } + /** + * Sets the override debug info flag + * When set to false the generated container will not override the __debugInfo method. + * + * @param bool $overrideDebugInfo + * @return void + */ + public function setOverrideDebugInfo(bool $overrideDebugInfo) : void + { + $this->overrideDebugInfo = $overrideDebugInfo; + } + /** * Get the current container full name * @@ -343,6 +362,10 @@ public function generate() : string $buffer .= $this->generateResolverMappings() . "\n"; $buffer .= $this->generateResolverMethods() . "\n"; + if ($this->overrideDebugInfo) { + $buffer .= $this->generateDebugInfo() . "\n"; + } + return $buffer . "\n}"; } @@ -555,4 +578,17 @@ private function generateResolverMethods() : string return $buffer; } + + private function generateDebugInfo() : string + { + return << \$this->available()]; + } + EOF; + } }