src/ServiceProvider/ServiceProviderLoader.php
private function extendService(string $serviceName, int $serviceProviderKey, callable $callable)
    {
        // TODO: check if $callable as a nullable previous argument!

        if (!$this->compiler->has($serviceName)) {
            // TODO: if $callable as NOT a nullable previous argument, throw an exception.
        }

        // The new service will be created under the name 'xxx_decorated_y'
        // The old service will be moved to the name 'xxx_decorated_y.inner'
        // This old service will be accessible through a callback represented by 'xxx_decorated_y.callbackwrapper'
        // The $servicename becomes an alias pointing to 'xxx_decorated_y'

        $previousDefinition = $this->compiler->getDumpableDefinition($serviceName);
        /*while ($previousDefinition instanceof Reference) {
            $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias());
        }*/

        while ($previousDefinition instanceof AliasDefinition) {
            $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias());
        }

        $oldServiceName = $serviceName;
        $decoratedServiceName = $this->getDecoratedServiceName($serviceName);
        //$innerName = $decoratedServiceName.'.inner';
        //$callbackWrapperName = $decoratedServiceName.'.callbackwrapper';

        // TODO: it would be way easier if we could simply rename a definition!!!
        if ($previousDefinition instanceof FactoryCallDefinition) {
            $innerDefinition = $previousDefinition->cloneWithoutIdentifier();
        } elseif ($previousDefinition instanceof CreateServiceFromRegistryDefinition) {
            $innerDefinition = $previousDefinition->cloneWithoutIdentifier();
        } elseif ($previousDefinition instanceof ExtendServiceFromRegistryDefinition) {
            $innerDefinition = $previousDefinition->cloneWithoutIdentifier();
        } else {
            // @codeCoverageIgnoreStart
            throw new CompilerException('Unable to rename definition from class '.get_class($previousDefinition));
            // @codeCoverageIgnoreEnd
        }

        $definition = $this->getExtendServiceDefinitionFromCallable($decoratedServiceName, $serviceName, $serviceProviderKey, $callable, new ContainerDefinition(), $innerDefinition);

        $this->compiler->addDumpableDefinition($definition);
        //$this->compiler->addDumpableDefinition($innerDefinition);
        //$this->compiler->addDumpableDefinition($callbackWrapperDefinition);
        $this->compiler->addDumpableDefinition(new AliasDefinition($oldServiceName, $decoratedServiceName));
    }
private function extendService(string $serviceName, int $serviceProviderKey, callable $callable)
    {
        // TODO: check if $callable as a nullable previous argument!

        if (!$this->compiler->has($serviceName)) {
            // TODO: if $callable as NOT a nullable previous argument, throw an exception.
        }

        // The new service will be created under the name 'xxx_decorated_y'
        // The old service will be moved to the name 'xxx_decorated_y.inner'
        // This old service will be accessible through a callback represented by 'xxx_decorated_y.callbackwrapper'
        // The $servicename becomes an alias pointing to 'xxx_decorated_y'

        $previousDefinition = $this->compiler->getDumpableDefinition($serviceName);
        /*while ($previousDefinition instanceof Reference) {
            $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias());
        }*/

        while ($previousDefinition instanceof AliasDefinition) {
            $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias());
        }

        $oldServiceName = $serviceName;
        $decoratedServiceName = $this->getDecoratedServiceName($serviceName);
        //$innerName = $decoratedServiceName.'.inner';
        //$callbackWrapperName = $decoratedServiceName.'.callbackwrapper';

        // TODO: it would be way easier if we could simply rename a definition!!!
        if ($previousDefinition instanceof FactoryCallDefinition) {
            $innerDefinition = $previousDefinition->cloneWithoutIdentifier();
        } elseif ($previousDefinition instanceof CreateServiceFromRegistryDefinition) {
            $innerDefinition = $previousDefinition->cloneWithoutIdentifier();
        } elseif ($previousDefinition instanceof ExtendServiceFromRegistryDefinition) {
            $innerDefinition = $previousDefinition->cloneWithoutIdentifier();
        } else {
            // @codeCoverageIgnoreStart
            throw new CompilerException('Unable to rename definition from class '.get_class($previousDefinition));
            // @codeCoverageIgnoreEnd
        }

        $definition = $this->getExtendServiceDefinitionFromCallable($decoratedServiceName, $serviceName, $serviceProviderKey, $callable, new ContainerDefinition(), $innerDefinition);

        $this->compiler->addDumpableDefinition($definition);
        //$this->compiler->addDumpableDefinition($innerDefinition);
        //$this->compiler->addDumpableDefinition($callbackWrapperDefinition);
        $this->compiler->addDumpableDefinition(new AliasDefinition($oldServiceName, $decoratedServiceName));
    }
@param string $serviceName
@param int $serviceProviderKey
@param callable $callable

@throws CompilerException