/**
* Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\BeanMethod}.
*
* @param MethodReflection $originalMethod
* @param Bean $beanMetadata
* @param Parameters $methodParameters
* @param $beanType
* @param ForceLazyInitProperty $forceLazyInitProperty
* @param SessionBeansProperty $sessionBeansProperty
* @param BeanPostProcessorsProperty $postProcessorsProperty
* @param BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty
* @param GetParameter $parameterValuesMethod
* @param WrapBeanAsLazy $wrapBeanAsLazy
* @return BeanMethod|MethodGenerator
*/
public static function generateMethod(MethodReflection $originalMethod, Bean $beanMetadata, Parameters $methodParameters, $beanType, ForceLazyInitProperty $forceLazyInitProperty, SessionBeansProperty $sessionBeansProperty, BeanPostProcessorsProperty $postProcessorsProperty, BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty, GetParameter $parameterValuesMethod, WrapBeanAsLazy $wrapBeanAsLazy)
{
$method = static::fromReflection($originalMethod);
$methodParams = static::convertMethodParamsToString($methodParameters, $parameterValuesMethod);
$beanId = $originalMethod->getName();
$body = '';
if (in_array($beanType, ['array', 'callable', 'bool', 'float', 'int', 'string'], true)) {
// return type is a primitive, simply call parent method and return immediately
$body .= 'return parent::' . $beanId . '(' . $methodParams . ');' . PHP_EOL;
} elseif (class_exists($beanType) || interface_exists($beanType)) {
if ($beanMetadata->isLazy()) {
$body = static::generateLazyBeanCode('', $beanId, $beanType, $beanMetadata, $methodParams, $forceLazyInitProperty, $sessionBeansProperty, $postProcessorsProperty, $beanFactoryConfigurationProperty);
} else {
$body = static::generateNonLazyBeanCode('', $beanId, $beanType, $beanMetadata, $methodParams, $forceLazyInitProperty, $sessionBeansProperty, $postProcessorsProperty, $beanFactoryConfigurationProperty, $wrapBeanAsLazy);
}
} else {
// return type is unknown, throw an exception
$body .= '$message = sprintf(' . PHP_EOL;
$body .= ' \'Either return type declaration missing or unkown for bean with id "' . $beanId . '": %s\',' . PHP_EOL;
$body .= ' $e->getMessage()' . PHP_EOL;
$body .= ');' . PHP_EOL;
$body .= 'throw new \\' . BeanException::class . '($message, 0, $e);' . PHP_EOL;
}
$method->setBody($body);
$method->setDocBlock('{@inheritDoc}');
return $method;
}