src/ContainerFactory.php
public function create(string $containerName, callable $builderCallback, array $initalParameters = []) : Container
    {
        if (class_exists($containerName))
        {
            return new $containerName;
        }

        $fileName = basename(str_replace("\\", '/', $containerName));
        $cacheFile = $this->cacheDirectory . $fileName . '.php';

        if ((!(file_exists($cacheFile) && is_readable($cacheFile))) || $this->isDebugMode())
        {
            $builder = new ContainerBuilder($containerName);

            // run the builder callback
            $builderCallback($builder);

            // store the cache file
            $cacheDir = dirname($cacheFile);

            if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
                throw new ContainerException("The directory \"{$cacheDir}\" is not writable. Cannot generate container class.");
            } elseif (is_file($cacheFile) && !is_writable($cacheFile)) {
                throw new ContainerException("The file \"{$cacheFile}\" is not writable. Cannot generate container class.");
            }

            file_put_contents($cacheFile, $builder->generate());
        }

        // require the generated cache file
        require_once $cacheFile;

        // create an instance of the generated container
        return new $containerName($initalParameters);
    }
public function create(string $containerName, callable $builderCallback, array $initalParameters = []) : Container
    {
        if (class_exists($containerName))
        {
            return new $containerName;
        }

        $fileName = basename(str_replace("\\", '/', $containerName));
        $cacheFile = $this->cacheDirectory . $fileName . '.php';

        if ((!(file_exists($cacheFile) && is_readable($cacheFile))) || $this->isDebugMode())
        {
            $builder = new ContainerBuilder($containerName);

            // run the builder callback
            $builderCallback($builder);

            // store the cache file
            $cacheDir = dirname($cacheFile);

            if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
                throw new ContainerException("The directory \"{$cacheDir}\" is not writable. Cannot generate container class.");
            } elseif (is_file($cacheFile) && !is_writable($cacheFile)) {
                throw new ContainerException("The file \"{$cacheFile}\" is not writable. Cannot generate container class.");
            }

            file_put_contents($cacheFile, $builder->generate());
        }

        // require the generated cache file
        require_once $cacheFile;

        // create an instance of the generated container
        return new $containerName($initalParameters);
    }
Create a container with the given name. You can pass an
array with services

@param string                $containerName
@param callable              $builderCallback
@param array                 $initalParameters

@return Container The generated container instnace.