public static function getInstance()
 {
     if (self::$db === null) {
         Database::connect();
     }
     return self::$db;
 }
 public function __construct(Collection $route_data, $db_connect = true, $store_view = false)
 {
     if (Config::$maintenance === true && $params->controller !== 'Unavailable') {
         $this->redirect('maintenance', [], false);
     }
     // Checking application is installed
     if ($route_data->controller !== 'Install' && Config::$app_id == '##APP_ID##') {
         $this->redirect('install');
     }
     $this->route_data = $route_data;
     $this->store = $store_view;
     $controller_namespace = $this->route_data->namespace . $this->route_data->controller . 'Controller';
     // Storing and cleaning POST, FILES, SESSION and GET data.
     $this->setGlobals();
     // Loading the translation tool with the default controller file language.
     if ($this->translation === null) {
         $this->translation = new Translation(['bundle' => $this->route_data->bundle, 'theme' => null, 'domain' => null]);
         $GLOBALS['twig_vars'] = array();
         $GLOBALS['twig_vars']['trans_bundle'] = $this->route_data->bundle;
         $GLOBALS['twig_vars']['trans_vars'] = array();
     }
     define('ROUTE_NAME', $this->route_data->route_name);
     define('BUNDLE_NAME', $this->route_data->bundle);
     $class_methods = array_diff(get_class_methods($controller_namespace), get_class_methods(get_parent_class($this)));
     $method = $this->route_data->method . 'Action';
     if (in_array($method, $class_methods)) {
         if ($db_connect === true && $route_data->controller !== 'Unavailable' && $route_data->controller !== 'Install' && Config::$dbms_to_use != '##DB_ENGINE##') {
             if (!\Sybil\ORM\Database::connect()) {
                 if (ENVIRONMENT == 'production') {
                     $this->redirect('unavailable');
                 } else {
                     App::translate("db_connection_failed", $this->translation, $this->trans_debug);
                     die;
                 }
             }
         }
         // Setting global vars for the view.
         $this->vars = new Collection();
         $this->vars->set('SITE_NAME', Config::$site_name == '##SITE_NAME##' ? FRAMEWORK_NAME : Config::$site_name);
         if ($this->session->has('auth_user')) {
             $this->vars->set('AUTH_USER', new Collection(['id' => $this->session->auth_user->id, 'role' => $this->session->auth_user->role]));
         }
         // Model autoloading
         $this->autoloadModels();
         // Calling the requested controller method.
         call_user_func_array([$this, $method], $this->route_data->params->toArray());
     } else {
         if (ENVIRONMENT == 'production') {
             if ($this->route_data->controller !== 'Error') {
                 $this->setError();
             } else {
                 $this->redirect('unavailable');
             }
         } else {
             $this->translation->setVar('method', $method);
             App::translate("controller_method_missing", $this->translation, $this->trans_debug);
             die;
         }
     }
 }
 public function __construct()
 {
     $this->db = Database::getInstance();
     // Translation tool
     if ($this->translation === null) {
         $this->translation = new Translation(['bundle' => false, 'theme' => 'sybil', 'domain' => 'database']);
     }
 }
 public function __construct()
 {
     $this->db = Database::getInstance();
     $this->db_name = Config::$databases[Config::$db_to_use]['dbname'];
 }