protected function buildLifecycleShutdownCode(Configuration $objectConfiguration, $cause)
    {
        $lifecycleShutdownMethodName = $objectConfiguration->getLifecycleShutdownMethodName();
        if (!$this->reflectionService->hasMethod($objectConfiguration->getClassName(), $lifecycleShutdownMethodName)) {
            return '';
        }
        $className = $objectConfiguration->getClassName();
        $code = "\n" . '        $isSameClass = get_class($this) === \'' . $className . '\';';
        if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED) {
            $code .= "\n" . '        $classParents = class_parents($this);';
            $code .= "\n" . '        $classImplements = class_implements($this);';
            $code .= "\n" . '        $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\ORM\Proxy\Proxy\', $classImplements) !== false;' . "\n";
            $code .= "\n" . '        if ($isSameClass || $isClassProxy) {' . "\n";
        } else {
            $code .= "\n" . '        if ($isSameClass) {' . "\n";
        }
        $code .= '        \Neos\Flow\Core\Bootstrap::$staticObjectManager->registerShutdownObject($this, \'' . $lifecycleShutdownMethodName . '\');' . PHP_EOL;
        $code .= '        }' . "\n";

        return $code;
    }