Inheritance: extends Zend\Code\Generator\PropertyGenerator
Example #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");
 }
Example #2
0
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\MagicSleep}.
  *
  * @param ReflectionClass $originalClass
  * @param SessionBeansProperty $aliasesProperty
  * @throws InvalidArgumentException
  */
 public function __construct(ReflectionClass $originalClass, SessionBeansProperty $aliasesProperty)
 {
     parent::__construct($originalClass, '__sleep');
     $this->setBody('return ["' . $aliasesProperty->getName() . '"];');
 }
Example #3
0
 /**
  * Helper method to generate the method body for managing non-lazy bean instances.
  *
  * @param string $padding
  * @param string $beanId
  * @param string $beanType
  * @param Bean $beanMetadata
  * @param string $methodParams
  * @param ForceLazyInitProperty $forceLazyInitProperty
  * @param SessionBeansProperty $sessionBeansProperty
  * @param BeanPostProcessorsProperty $postProcessorsProperty
  * @param BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty
  * @param WrapBeanAsLazy $wrapBeanAsLazy
  * @return string
  */
 protected static function generateNonLazyBeanCode(string $padding, string $beanId, string $beanType, Bean $beanMetadata, string $methodParams, ForceLazyInitProperty $forceLazyInitProperty, SessionBeansProperty $sessionBeansProperty, BeanPostProcessorsProperty $postProcessorsProperty, BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty, WrapBeanAsLazy $wrapBeanAsLazy) : string
 {
     $content = $padding . '$backupForceLazyInit = $this->' . $forceLazyInitProperty->getName() . ';' . PHP_EOL;
     if ($beanMetadata->isSession()) {
         $content .= $padding . 'if($this->' . $sessionBeansProperty->getName() . '->has("' . $beanId . '")) {' . PHP_EOL;
         if ($beanMetadata->isSingleton()) {
             $content .= $padding . '    $sessionInstance = clone $this->' . $sessionBeansProperty->getName() . '->get("' . $beanId . '");' . PHP_EOL;
         } else {
             $content .= $padding . '    $sessionInstance = $this->' . $sessionBeansProperty->getName() . '->get("' . $beanId . '");' . PHP_EOL;
         }
         $content .= $padding . '    return ($backupForceLazyInit) ? $this->' . $wrapBeanAsLazy->getName() . '("' . $beanId . '", "' . $beanType . '", $sessionInstance) : $sessionInstance;' . PHP_EOL;
         $content .= $padding . '}' . PHP_EOL;
     }
     if ($beanMetadata->isSingleton()) {
         $content .= $padding . 'static $instance = null;' . PHP_EOL;
         $content .= $padding . 'if ($instance !== null) {' . PHP_EOL;
         $content .= $padding . '    return ($backupForceLazyInit) ? $this->' . $wrapBeanAsLazy->getName() . '("' . $beanId . '", "' . $beanType . '", $instance) : $instance;' . PHP_EOL;
         $content .= $padding . '}' . PHP_EOL;
     }
     if ($beanMetadata->isSession()) {
         $content .= $padding . '$this->' . $forceLazyInitProperty->getName() . ' = true;' . PHP_EOL;
     }
     $content .= self::generateBeanCreationCode($padding, $beanId, $methodParams, $postProcessorsProperty);
     if ($beanMetadata->isSession()) {
         $content .= $padding . '$this->' . $forceLazyInitProperty->getName() . ' = $backupForceLazyInit;' . PHP_EOL;
         $content .= $padding . '$this->' . $sessionBeansProperty->getName() . '->add("' . $beanId . '", $instance);' . PHP_EOL;
     }
     $content .= $padding . 'return ($backupForceLazyInit) ? $this->' . $wrapBeanAsLazy->getName() . '("' . $beanId . '", "' . $beanType . '", $instance) : $instance;' . PHP_EOL;
     return $content;
 }