public static function Config($config) { // check config if (empty($config)) { throw new MVCException('Config cannot be empty', self::$Code['CONFIG_EMPTY']); } if (empty($config['path'])) { throw new MVCException('Config path cannot be empty', self::$Code['CONFIG_PATH_EMPTY_OR_NOT_EXISTS']); } // check path and fix with separator $path = $config['path']; if (!file_exists($path) || !is_dir($path)) { throw new MVCException('Config path not exists', self::$Code['CONFIG_PATH_EMPTY_OR_NOT_EXISTS']); } if (substr($path, -1) != DIRECTORY_SEPARATOR) { $path .= DIRECTORY_SEPARATOR; } self::$Path = $path; // merge config self::$Config = array_merge(self::$Config, $config); // check routes if (empty(self::$Config['routes'])) { throw new MVCException('Config routes cannot be empty', self::$Code['CONFIG_ROUTE_EMPTY_OR_INVALIDE']); } foreach (self::$Config['routes'] as $route) { if (empty($route['controller']) || empty($route['action'])) { throw new MVCException('Config routes is invalide', self::$Code['CONFIG_ROUTE_EMPTY_OR_INVALIDE']); } } // model db if (isset(self::$Config['model']['db'])) { self::$DB = self::$Config['model']['db']; } // registor autoload spl_autoload_register('MVC::Autoload'); }