src/Valkyrja/Container/NativeContainer.php
public function setup(bool $force = false, bool $useCache = true): void
    {
        if (self::$setup && ! $force) {
            return;
        }

        self::$setup = true;

        // If the application should use the container cache files
        if ($useCache && $this->app->config()['container']['useCache']) {
            $this->setupFromCache();

            // Then return out of setup
            return;
        }

        self::$registered = [];
        self::$services   = [];
        self::$provided   = [];

        $useAnnotations     = $this->app->config(
            'container.useAnnotations',
            false
        );
        $annotationsEnabled = $this->app->config(
            'annotations.enabled',
            false
        );
        $onlyAnnotations    = $this->app->config(
            'container.useAnnotationsExclusively',
            false
        );

        // Setup service providers
        $this->setupServiceProviders();

        // If annotations are enabled and the container should use annotations
        if ($useAnnotations && $annotationsEnabled) {
            // Setup annotated services, contexts, and aliases
            $this->setupAnnotations();

            // If only annotations should be used
            if ($onlyAnnotations) {
                // Return to avoid loading container file
                return;
            }
        }

        // Include the container file
        // NOTE: Included if annotations are set or not due to possibility of
        // container items being defined within the classes as well as within
        // the container file
        require $this->app->config()['container']['filePath'];
    }
public function setup(bool $force = false, bool $useCache = true): void
    {
        if (self::$setup && ! $force) {
            return;
        }

        self::$setup = true;

        // If the application should use the container cache files
        if ($useCache && $this->app->config()['container']['useCache']) {
            $this->setupFromCache();

            // Then return out of setup
            return;
        }

        self::$registered = [];
        self::$services   = [];
        self::$provided   = [];

        $useAnnotations     = $this->app->config(
            'container.useAnnotations',
            false
        );
        $annotationsEnabled = $this->app->config(
            'annotations.enabled',
            false
        );
        $onlyAnnotations    = $this->app->config(
            'container.useAnnotationsExclusively',
            false
        );

        // Setup service providers
        $this->setupServiceProviders();

        // If annotations are enabled and the container should use annotations
        if ($useAnnotations && $annotationsEnabled) {
            // Setup annotated services, contexts, and aliases
            $this->setupAnnotations();

            // If only annotations should be used
            if ($onlyAnnotations) {
                // Return to avoid loading container file
                return;
            }
        }

        // Include the container file
        // NOTE: Included if annotations are set or not due to possibility of
        // container items being defined within the classes as well as within
        // the container file
        require $this->app->config()['container']['filePath'];
    }
Setup the container.

@param bool $force    [optional] Whether to force setup
@param bool $useCache [optional] Whether to use cache

@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