Inheritance: extends Zend\Code\Generator\PropertyGenerator
Beispiel #1
0
 /**
  * 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");
 }
Beispiel #2
0
 /**
  * Helper method to generate the code to initialize a bean.
  *
  * @param string $padding
  * @param string $beanId
  * @param string $methodParams
  * @param BeanPostProcessorsProperty $postProcessorsProperty
  * @return string
  */
 protected static function generateBeanCreationCode(string $padding, string $beanId, string $methodParams, BeanPostProcessorsProperty $postProcessorsProperty) : string
 {
     $content = $padding . '$instance = parent::' . $beanId . '(' . $methodParams . ');' . PHP_EOL;
     $content .= $padding . 'if ($instance instanceof \\' . InitializedBean::class . ') {
     ' . PHP_EOL;
     $content .= $padding . '    $instance->postInitialization();' . PHP_EOL;
     $content .= $padding . '}' . PHP_EOL;
     $content .= PHP_EOL;
     $content .= $padding . 'foreach ($this->' . $postProcessorsProperty->getName() . ' as $postProcessor) {
     ' . PHP_EOL;
     $content .= $padding . '    $postProcessor->postProcess($instance, "' . $beanId . '");' . PHP_EOL;
     $content .= $padding . '}' . PHP_EOL;
     return $content;
 }