/** * Retrieve the CSRF token for the current request. * * @return string The CSRF token */ private static function token() { if (static::$token !== null) { return static::$token; } $token = Str::random(32); // Store the new token Session::set(self::SESSION_KEY, $token); return static::$token = $token; }
/** * Create a new request for the application. */ public function __construct() { $this->router = new Router(); $this->method = strtoupper($this->router->requestMethod()); // Store the raw input data $input = array_merge($_GET, $_POST); $this->rawInput = new Input($input); // Escape the input data, and store it again $input = $this->escapeInput($input); $this->input = new Input($input); // Store the current URI if (isset($_SERVER['REQUEST_URI'])) { $this->uri = $_SERVER['REQUEST_URI']; } // Retrieve the previous URI from the session, and store it // against the request object if (($previous = Session::get('previous_uri')) !== null) { $this->previousUri = $previous; } // Update the previous URI session key now that we have retrieved // it's value Session::set('previous_uri', $this->uri); }
/** * 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(); } }