/** * Create a new application instance. */ public function __construct() { // Store the instance statically static::$instance = $this; // Load the app's config $this->loadConfig(); // Register the error handler $this->registerErrorHandler(); // Create our request and response objects $this->request = new Request(); $this->response = new Response(); // Bootstrap the database Database::bootstrap($this->config->db->toArray()); // Convert relative store paths to absolute, and bootstrap the cache foreach ($this->config->cache as $instance => $config) { $cacheStorePath = $config->store_path; if ($cacheStorePath !== null) { if (!is_dir($cacheStorePath) && is_dir(APP_ROOT . $cacheStorePath)) { $this->config->cache->{$instance}->store_path = APP_ROOT . $cacheStorePath; } } } Cache::bootstrap($this->config->cache->toArray()); // Convert relative store paths to absolute, and bootstrap the session $sessionStorePath = $this->config->session->store_path; if ($sessionStorePath !== null) { if (!is_dir($sessionStorePath) && is_dir(APP_ROOT . $sessionStorePath)) { $this->config->session->store_path = APP_ROOT . $sessionStorePath; } } Session::bootstrap($this->config->session); // Include the app routes require APP_ROOT . 'routes.php'; // Register global view variables View::addGlobal('appName', $this->config->app->name); View::addGlobal('app', $this); View::addGlobal('input', $this->request->input); $this->compileAssets(); // Execute routes Router::execute(); if (PHP_SAPI !== 'cli') { $this->checkRoute(); } }
/** * Compile a view and return the rendered output. * * @param string $name The name of the view (relative to app/views) * @param array $vars Variables to pass to the view * @param array $options Rendering options to pass to the view * * @return string The compiled HTML */ function view($name, array $vars = [], array $options = []) { $view = new View($name, $vars, $options); return $view->render(); }