3 declare(strict_types=1);
5 namespace CuyZ\Valinor\Definition\Repository\Cache\Compiler;
7 use CuyZ\Valinor\Definition\ParameterDefinition;
10 final class ParameterDefinitionCompiler
12 public function __construct(
13 private TypeCompiler $typeCompiler,
14 private AttributesCompiler $attributesCompiler
17 public function compile(ParameterDefinition $parameter): string
19 $isOptional = var_export($parameter->isOptional(), true);
20 $isVariadic = var_export($parameter->isVariadic(), true);
21 $defaultValue = $this->defaultValue($parameter);
22 $type = $this->typeCompiler->compile($parameter->type());
23 $attributes = $this->attributesCompiler->compile($parameter->attributes());
26 new \CuyZ\Valinor\Definition\ParameterDefinition(
27 '{$parameter->name()}',
28 '{$parameter->signature()}',
38 private function defaultValue(ParameterDefinition $parameter): string
40 $defaultValue = $parameter->defaultValue();
42 return is_object($defaultValue)
43 ? 'unserialize(' . var_export(serialize($defaultValue), true) . ')'
44 : var_export($defaultValue, true);