src/Valkyrja/Container/NativeContainer.php
public function context(ServiceContext $serviceContext): void
    {
        $context        = $serviceContext->getClass()
            ?? $serviceContext->getFunction();
        $member         = $serviceContext->getMethod()
            ?? $serviceContext->getProperty();
        $contextContext = $serviceContext->getContextClass()
            ?? $serviceContext->getContextFunction();

        // If the context index is null then there's no context
        if (null === $context || null === $serviceContext->getId()) {
            throw new InvalidContextException('Invalid context.');
        }

        // If the context is the same as the end service dispatch and the
        // dispatch isn't static throw an error to disallow this kind of
        // context as it will create an endless loop where the dispatcher
        // will attempt to create the callable with the dependencies and the
        // hasContext check in Container::get() will keep catching it
        if ($context === $contextContext && ! $serviceContext->isStatic()) {
            throw new EndlessContextLoopException(
                'This kind of context will create'
                . 'an endless loop where the dispatcher will attempt to create the '
                . 'callable with the dependencies and the hasContext check in '
                . 'Container::get() will keep catching it: '
                . $this->contextServiceId(
                    $serviceContext->getId(),
                    $context,
                    $member
                )
            );
        }

        $service = $this->getServiceFromContext(
            $serviceContext,
            $context,
            $member
        );

        $this->bind($service);
    }
public function context(ServiceContext $serviceContext): void
    {
        $context        = $serviceContext->getClass()
            ?? $serviceContext->getFunction();
        $member         = $serviceContext->getMethod()
            ?? $serviceContext->getProperty();
        $contextContext = $serviceContext->getContextClass()
            ?? $serviceContext->getContextFunction();

        // If the context index is null then there's no context
        if (null === $context || null === $serviceContext->getId()) {
            throw new InvalidContextException('Invalid context.');
        }

        // If the context is the same as the end service dispatch and the
        // dispatch isn't static throw an error to disallow this kind of
        // context as it will create an endless loop where the dispatcher
        // will attempt to create the callable with the dependencies and the
        // hasContext check in Container::get() will keep catching it
        if ($context === $contextContext && ! $serviceContext->isStatic()) {
            throw new EndlessContextLoopException(
                'This kind of context will create'
                . 'an endless loop where the dispatcher will attempt to create the '
                . 'callable with the dependencies and the hasContext check in '
                . 'Container::get() will keep catching it: '
                . $this->contextServiceId(
                    $serviceContext->getId(),
                    $context,
                    $member
                )
            );
        }

        $service = $this->getServiceFromContext(
            $serviceContext,
            $context,
            $member
        );

        $this->bind($service);
    }
Bind a context to the container.

@param ServiceContext $serviceContext The context service

@throws \Valkyrja\Container\Exceptions\InvalidContextException
@throws \Valkyrja\Container\Exceptions\EndlessContextLoopException
@throws \Valkyrja\Container\Exceptions\InvalidServiceIdException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidClosureException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidDispatchCapabilityException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidFunctionException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidMethodException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidPropertyException

@return void