/** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\GetParameter}. * * @param ReflectionClass $originalClass * @param ParameterValuesProperty $parameterValueProperty * @throws InvalidArgumentException */ public function __construct(ReflectionClass $originalClass, ParameterValuesProperty $parameterValueProperty) { parent::__construct('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); }
/** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\Constructor}. * * @param ReflectionClass $originalClass * @param ParameterValuesProperty $parameterValuesProperty * @param SessionBeansProperty $sessionBeansProperty * @param BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty * @param BeanPostProcessorsProperty $beanPostProcessorsProperty * @param string[] $beanPostProcessorMethodNames */ public function __construct(ReflectionClass $originalClass, ParameterValuesProperty $parameterValuesProperty, SessionBeansProperty $sessionBeansProperty, BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty, BeanPostProcessorsProperty $beanPostProcessorsProperty, array $beanPostProcessorMethodNames) { parent::__construct('__construct'); $beanFactoryConfigurationParameter = new ParameterGenerator('config'); $beanFactoryConfigurationParameter->setType(BeanFactoryConfiguration::class); $parametersParameter = new ParameterGenerator('params'); $parametersParameter->setDefaultValue([]); $body = '$this->' . $parameterValuesProperty->getName() . ' = $' . $parametersParameter->getName() . ';' . PHP_EOL; $body .= '$this->' . $beanFactoryConfigurationProperty->getName() . ' = $' . $beanFactoryConfigurationParameter->getName() . ';' . PHP_EOL; $body .= '$this->' . $sessionBeansProperty->getName() . ' = $' . $beanFactoryConfigurationParameter->getName() . '->getSessionBeanStore();' . PHP_EOL; $body .= '// register {@link \\bitExpert\\Disco\\BeanPostProcessor} instances' . PHP_EOL; $body .= '$this->' . $beanPostProcessorsProperty->getName() . '[] = new \\bitExpert\\Disco\\BeanFactoryPostProcessor();' . PHP_EOL; foreach ($beanPostProcessorMethodNames as $methodName) { $body .= '$this->' . $beanPostProcessorsProperty->getName() . '[] = $this->' . $methodName . '(); '; $body .= PHP_EOL; } $this->setParameter($beanFactoryConfigurationParameter); $this->setParameter($parametersParameter); $this->setBody($body); $this->setDocBlock("@override constructor"); }