*/ class ObjectDefinitionDumper { /** * Returns the definition as string representation. */ public function dump(ObjectDefinition $definition): string { $className = $definition->getClassName(); $classExist = class_exists($className) || interface_exists($className); // Class if (! $classExist) { $warning = '#UNKNOWN# '; } else { $class = new \ReflectionClass($className); $warning = $class->isInstantiable() ? '' : '#NOT INSTANTIABLE# '; } $str = sprintf(' class = %s%s', $warning, $className); // Lazy $str .= \PHP_EOL . ' lazy = ' . var_export($definition->isLazy(), true); if ($classExist) { // Constructor $str .= $this->dumpConstructor($className, $definition); // Properties $str .= $this->dumpProperties($definition); // Methods $str .= $this->dumpMethods($className, $definition); } return sprintf('Object (' . \PHP_EOL . '%s' . \PHP_EOL . ')', $str); } private function dumpConstructor(string $className, ObjectDefinition $definition): string { $str = ''; $constructorInjection = $definition->getConstructorInjection(); if ($constructorInjection !== null) { $parameters = $this->dumpMethodParameters($className, $constructorInjection); $str .= sprintf(\PHP_EOL . ' __construct(' . \PHP_EOL . ' %s' . \PHP_EOL . ' )', $parameters); } return $str; } private function dumpProperties(ObjectDefinition $definition): string { $str = ''; foreach ($definition->getPropertyInjections() as $propertyInjection) { $value = $propertyInjection->getValue(); $valueStr = $value instanceof Definition ? (string) $value : var_export($value, true); $str .= sprintf(\PHP_EOL . ' $%s = %s', $propertyInjection->getPropertyName(), $valueStr); } return $str; } private function dumpMethods(string $className, ObjectDefinition $definition): string { $str = ''; foreach ($definition->getMethodInjections() as $methodInjection) { $parameters = $this->dumpMethodParameters($className, $methodInjection); $str .= sprintf(\PHP_EOL . ' %s(' . \PHP_EOL . ' %s' . \PHP_EOL . ' )', $methodInjection->getMethodName(), $parameters); } return $str; } private function dumpMethodParameters(string $className, MethodInjection $methodInjection): string { $methodReflection = new \ReflectionMethod($className, $methodInjection->getMethodName()); $args = []; $definitionParameters = $methodInjection->getParameters(); foreach ($methodReflection->getParameters() as $index => $parameter) { if (array_key_exists($index, $definitionParameters)) { $value = $definitionParameters[$index]; $valueStr = $value instanceof Definition ? (string) $value : var_export($value, true); $args[] = sprintf('$%s = %s', $parameter->getName(), $valueStr); continue; } // If the parameter is optional and wasn't specified, we take its default value if ($parameter->isOptional()) { try { $value = $parameter->getDefaultValue(); $args[] = sprintf( '$%s = (default value) %s', $parameter->getName(), var_export($value, true) ); continue; } catch (ReflectionException $e) { // The default value can't be read through Reflection because it is a PHP internal class } } $args[] = sprintf('$%s = #UNDEFINED#', $parameter->getName()); } return implode(\PHP_EOL . ' ', $args); } } __halt_compiler();----SIGNATURE:----OJPwgxUPaCoLXTyIHUWt6dpBwkY5ZT2sYhZpNNyApjOlblNxk92kYMdgZjqmayLp+ytXENlt2O6kpumZWm7IMSbMhXcAR7/3d5DbHQDWXFlNnmmrkE1cRmF9EdFJ0ssua+Vm7/ypp2CmqRfGVef9cAEmYSiYY7ABbVHEx3AVEG1BCl3gcML17/gsJ/CM0dyDIeDFTU6bb6+Oq8lgC2tE6qdHMG4G7pwe1xYYWlOVYQi8knTHxUlQ6gio2Z9LdSefgOkBM8syAV8gT266CQnAjluMgC62ClzpTPurMWPXL/ONQF5Gjpw/S41B0BoZMPTgKPPXDeHN+las1i2jaerDvQRLikVFSa8FiQiU4vjRLKCdcS6YRsX7jNFzZesu2AqU/XQDXUGqkXuNL/EjNVCbd/RrnZfYLsZqCnVdMQyPfPTnqcLRVxTzSlfLWh6LmwOPuChHTr+0A7+6LcY/xom4ENXUpS44+1mPjuuw9dGnAFztyLZJSdpiGVgp+LTpfeRIvP8o+RxB0VPZc9uzSjYHj3ucKEo1XpLaBcCFkbfO+hgf3jYElVRPNBywy+5jy00UM8xUHsUVV2cSJujD9tmcj5rU7B3BRrnIVzDB+q7rT7Y+v3w3sfi5QWXZ6OXD9eRkUO+eBN/wYXvtGJePDxptkcMTY8oQRj23bx8QSAGBTUQ=----ATTACHMENT:----NDE1OTk5OTU5Nzc0ODY4IDIxMTc4NDMzOTk3MDQyMDYgNjkwNTQ1OTk1MTc2Njg4NQ==