bitExpert\Disco\Proxy\Configuration\MethodGenerator\GetParameter::__construct PHP Method

__construct() public method

Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\GetParameter}.
public __construct ( ReflectionClass $originalClass, ParameterValuesProperty $parameterValueProperty )
$originalClass ReflectionClass
$parameterValueProperty bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ParameterValuesProperty
    public function __construct(ReflectionClass $originalClass, ParameterValuesProperty $parameterValueProperty)
    {
        parent::__construct(UniqueIdentifierGenerator::getIdentifier('getParameter'));
        $propertyNameParameter = new ParameterGenerator('propertyName');
        $requiredParameter = new ParameterGenerator('required');
        $requiredParameter->setDefaultValue(true);
        $defaultValueParameter = new ParameterGenerator('defaultValue');
        $defaultValueParameter->setDefaultValue(null);
        $body = '$steps = explode(\'.\', $' . $propertyNameParameter->getName() . ');' . PHP_EOL;
        $body .= '$value = $this->' . $parameterValueProperty->getName() . ';' . PHP_EOL;
        $body .= '$currentPath = [];' . PHP_EOL;
        $body .= 'foreach ($steps as $step) {' . PHP_EOL;
        $body .= '    $currentPath[] = $step;' . PHP_EOL;
        $body .= '    if (isset($value[$step])) {' . PHP_EOL;
        $body .= '        $value = $value[$step];' . PHP_EOL;
        $body .= '    } else {' . PHP_EOL;
        $body .= '        $value = $' . $defaultValueParameter->getName() . ';' . PHP_EOL;
        $body .= '        break;' . PHP_EOL;
        $body .= '    }' . PHP_EOL;
        $body .= '}' . PHP_EOL . PHP_EOL;
        $body .= 'if ($' . $requiredParameter->getName() . ' && (null === $value)) {' . PHP_EOL;
        $body .= '    if (null === $' . $defaultValueParameter->getName() . ') {' . PHP_EOL;
        $body .= '        throw new \\RuntimeException(\'Parameter "\' .$' . $propertyNameParameter->getName() . '. \'" is required but not defined and no default value provided!\');' . PHP_EOL;
        $body .= '    }' . PHP_EOL;
        $body .= '    throw new \\RuntimeException(\'Parameter "\' .$' . $propertyNameParameter->getName() . '. \'" not defined!\');' . PHP_EOL;
        $body .= '}' . PHP_EOL . PHP_EOL;
        $body .= 'return $value;' . PHP_EOL;
        $this->setParameter($propertyNameParameter);
        $this->setParameter($requiredParameter);
        $this->setParameter($defaultValueParameter);
        $this->setVisibility(self::VISIBILITY_PROTECTED);
        $this->setBody($body);
    }
GetParameter