/** * Start the application. */ static function start($dispatch = true) { ob_start(); // Set error reporting level. error_reporting(E_ALL ^ E_NOTICE); // Setup default error handelers. set_error_handler(array('Request', 'default_error_handler'), E_ALL); set_exception_handler(array('Request', 'default_exception_handler')); // Setup autoloader. spl_autoload_register(array('Request', 'autoload')); // Load app config. self::$config = new Config('app'); $config =& self::$config; // Get current environment (default local). self::$env = is_file(APP_ROOT . 'config/.env') ? trim(file_get_contents(APP_ROOT . 'config/.env')) : 'local'; // Load environment config. if (is_file(APP_ROOT . 'config/' . self::$env . '.yml')) { self::$env_config = new Config(self::$env); $env_config =& self::$env_config; // Merge environment config into app config. $config = Config::merge($config, $env_config); } // Setup app defaults. $default_app_config = array('view_path' => APP_ROOT . 'app/templates/', 'public_path' => APP_ROOT . 'public/', 'default_controller' => 'index', 'default_action' => 'index', 'default_output' => 'html', 'default_layout' => 'default', 'default_locale' => 'en_US.UTF-8', 'ajax_layout' => null); $config->app = Config::merge($default_app_config, $config->app); // Setup default locale. setlocale(LC_ALL, $config->app['default_locale']); // Setup default route. if (!is_array($config->routes)) { $config->routes = array(); } array_push($config->routes, array('/')); array_push($config->routes, array('/:controller/:action/*')); // Include core and app helpers. self::include_helpers(APP_ROOT . 'app/helpers/'); self::include_helpers(APP_ROOT . 'core/helpers/'); // Include core and app models. self::include_models(APP_ROOT . 'app/models/', false); self::include_models(APP_ROOT . 'core/models/', false); // Include core and app plugins. self::include_plugins(APP_ROOT . 'app/plugins/'); self::include_plugins(APP_ROOT . 'core/plugins/'); // Dispatch request? if ($dispatch) { return self::dispatch($_SERVER['REQUEST_URI'] ?: $_SERVER['argv'][1]); } }