src/Config.php
public static function fromEnvironment(
        EnvironmentInterface $environment,
        string $directory = './config'
    ): ConfigInterface
    {
        $name = $environment->name();
        $projectRoot = $environment->projectRoot();

        // get the config directory
        $directory = (strpos($directory, '/') === 0 ? $directory : $projectRoot . substr($directory, 1));

        $config = [];
        foreach (new \DirectoryIterator($directory) as $file) {
            if ($file->isDot() || $file->getExtension() !== 'php') {
                continue;
            }

            // get the file parts
            $parts = explode('.', $file->getFilename());

            $namespace = $parts[0];
            $fileEnvironment = (count($parts) === 3 ? $parts[1] : EnvironmentInterface::ENV_PRODUCTION);

            if ($fileEnvironment === EnvironmentInterface::ENV_PRODUCTION && ! array_key_exists($namespace, $config)) {
                // use the production configs by default
                $config[$namespace] = new File($file->getPathname());
            }

            if ($fileEnvironment === $name) {
                // create the file resolver so we can resolve the
                $config[$namespace] = new File($file->getPathname());
            }
        }

        // add the environment variables to the config
        $config['environment'] = [
            'name' => $name,
            'projectRoot' => $projectRoot,
        ];

        return new static($config);
    }
public static function fromEnvironment(
        EnvironmentInterface $environment,
        string $directory = './config'
    ): ConfigInterface
    {
        $name = $environment->name();
        $projectRoot = $environment->projectRoot();

        // get the config directory
        $directory = (strpos($directory, '/') === 0 ? $directory : $projectRoot . substr($directory, 1));

        $config = [];
        foreach (new \DirectoryIterator($directory) as $file) {
            if ($file->isDot() || $file->getExtension() !== 'php') {
                continue;
            }

            // get the file parts
            $parts = explode('.', $file->getFilename());

            $namespace = $parts[0];
            $fileEnvironment = (count($parts) === 3 ? $parts[1] : EnvironmentInterface::ENV_PRODUCTION);

            if ($fileEnvironment === EnvironmentInterface::ENV_PRODUCTION && ! array_key_exists($namespace, $config)) {
                // use the production configs by default
                $config[$namespace] = new File($file->getPathname());
            }

            if ($fileEnvironment === $name) {
                // create the file resolver so we can resolve the
                $config[$namespace] = new File($file->getPathname());
            }
        }

        // add the environment variables to the config
        $config['environment'] = [
            'name' => $name,
            'projectRoot' => $projectRoot,
        ];

        return new static($config);
    }
public static function fromEnvironment ( EnvironmentInterface $ environment , string $ directory = './config' ) : ConfigInterface { $ name = $ environment -> name ( ) ; $ projectRoot = $ environment -> projectRoot ( ) ; // get the config directory $ directory = ( strpos ( $ directory , '/' ) === 0 ? $ directory : $ projectRoot . substr ( $ directory , 1 ) ) ; $ config = [ ] ; foreach ( new \ DirectoryIterator ( $ directory ) as $ file ) { if ( $ file -> isDot ( ) || $ file -> getExtension ( ) !== 'php' ) { continue ; } // get the file parts $ parts = explode ( '.' , $ file -> getFilename ( ) ) ; $ namespace = $ parts [ 0 ] ; $ fileEnvironment = ( count ( $ parts ) === 3 ? $ parts [ 1 ] : EnvironmentInterface :: ENV_PRODUCTION ) ; if ( $ fileEnvironment === EnvironmentInterface :: ENV_PRODUCTION && ! array_key_exists ( $ namespace , $ config ) ) { // use the production configs by default $ config [ $ namespace ] = new File ( $ file -> getPathname ( ) ) ; } if ( $ fileEnvironment === $ name ) { // create the file resolver so we can resolve the $ config [ $ namespace ] = new File ( $ file -> getPathname ( ) ) ; } } // add the environment variables to the config $ config [ 'environment' ] = [ 'name' => $ name , 'projectRoot' => $ projectRoot , ] ; return new static ( $ config ) ; }
From the environment object

@param EnvironmentInterface $environment
@param string $directory To be relative to the environment project root use ./config or /configs for full path
@return ConfigInterface
From the environment object