public static function loadConfig($configuration = [])
    {
        $configDir = static::getConfigDir();
        if (empty($configuration)) {
            $configFile = $configDir.'/config.php';
            // @codeCoverageIgnoreStart
            if (!is_file($configFile)) {
                throw new InvalidArgumentException(sprintf(
                    'Can not load config file "%s". Please be sure that this file exists and readable',
                    $configFile
                ));
            }
            // @codeCoverageIgnoreEnd
            $configuration = include $configFile;
        }


        $isCli = php_sapi_name() === 'cli';

        // load modules
        $modules = $configuration['modules'];
        $modules = static::generateModuleConfiguration($modules);

        $yawikConfig = $configDir.'/autoload/yawik.config.global.php';
        $installMode = false;
        if (!$isCli && !file_exists($yawikConfig)) {
            $modules = static::generateModuleConfiguration(['Install']);
            $installMode = true;
        } elseif (in_array('Install', $modules)) {
            $modules = array_diff($modules, ['Install']);
        }

        static::$env = $env = getenv('APPLICATION_ENV') ?: 'production';
        $defaults = [
            'module_listener_options' => [
                'module_paths' => [
                    './module',
                    './vendor',
                    './modules'
                ],
                // What configuration files should be autoloaded
                'config_glob_paths' => [
                    sprintf($configDir.'/autoload/{,*.}{global,%s,local}.php', $env)
                ],

                // Use the $env value to determine the state of the flag
                // caching disabled during install mode
                'config_cache_enabled' => ($env == 'production'),


                // Use the $env value to determine the state of the flag
                'module_map_cache_enabled' => ($env == 'production'),

                'module_map_cache_key' => 'module_map',

                // Use the $env value to determine the state of the flag
                'check_dependencies' => ($env != 'production'),

                'cache_dir' => getcwd()."/var/cache",
            ],
        ];

        $envConfig = [];
        $envConfigFile = $configDir.'/config.'.$env.'.php';
        if (file_exists($envConfigFile)) {
            if (is_readable($envConfigFile)) {
                $envConfig = include $envConfigFile;
            } else {
                \trigger_error(
                    sprintf('Environment config file "%s" is not readable.', $envConfigFile),
                    E_USER_NOTICE
                );
            }
        }

        // configuration file always win
        $configuration = ArrayUtils::merge($defaults, $configuration);
        // environment config always win
        $configuration = ArrayUtils::merge($configuration, $envConfig);

        $configuration['modules'] = $modules;

        // force disabled cache when in install mode
        if ($installMode) {
            $configuration['module_listener_options']['config_cache_enabled'] = false;
            $configuration['module_listener_options']['module_map_cache_enabled'] = false;
        }

        // setup docker environment
        if (getenv('DOCKER_ENV')=='yes') {
            $configuration = ArrayUtils::merge($configuration, static::getDockerEnv($configuration));
        }
        return $configuration;
    }