src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php
protected static function generateNonLazyBeanCode(
        string $padding,
        string $beanId,
        string $beanType,
        Bean $beanMetadata,
        string $methodParams,
        ForceLazyInitProperty $forceLazyInitProperty,
        SessionBeansProperty $sessionBeansProperty,
        BeanPostProcessorsProperty $postProcessorsProperty,
        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;
    }
protected static function generateNonLazyBeanCode(
        string $padding,
        string $beanId,
        string $beanType,
        Bean $beanMetadata,
        string $methodParams,
        ForceLazyInitProperty $forceLazyInitProperty,
        SessionBeansProperty $sessionBeansProperty,
        BeanPostProcessorsProperty $postProcessorsProperty,
        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;
    }
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 WrapBeanAsLazy $wrapBeanAsLazy
@return string