Esempio n. 1
-2
 public function __construct($debug = false)
 {
     define('DEBUG', $debug);
     /**
      * Initialize whoops to handle exceptions
      */
     Registry::set('whoops', new Run());
     if (DEBUG) {
         Registry::get('whoops')->pushHandler(new PrettyPageHandler());
     }
     Registry::get('whoops')->pushHandler(new ExceptionHandler());
     Registry::get('whoops')->register();
     if (!defined('BACBOX_APP')) {
         throw new Exception("Please define the path to the app directory in your bootstrap by setting BACBOX_APP");
     }
     /**
      * set some basic php configuration parameters
      * these are mainly used for new installations and
      * will be overriden later based on configuration tokens
      */
     ini_set('display_errors', (bool) $debug);
     ini_set('error_reporting', E_ALL ^ E_STRICT);
     ini_set('max_execution_time', 30);
     // define paths
     define('DS', preg_match("/\\//", __DIR__) ? "/" : "\\");
     define('BACBOX_LIB', __DIR__);
     define('BACBOX_SRC', BACBOX_APP . '../src' . DS);
     // set the bacbox urlbase, e.g. /bacbox/
     $urlbase = dirname($_SERVER['SCRIPT_NAME']);
     $urlbase = preg_replace('#\\\\+#', '/', $urlbase);
     if (!preg_match('#/$#', $urlbase)) {
         $urlbase .= "/";
     }
     define('BACBOX_URLBASE', $urlbase);
     // setup cache
     phpFastCache::setup('storage', 'files');
     phpFastCache::setup('path', BACBOX_APP . 'cache');
     phpFastCache::setup('securityKey', 'phpFastCache');
     // initialize Uberloader
     $loader = new Uberloader();
     $loader->set_cache_backend(new UberloaderCacheBackendFilesystem(BACBOX_APP . "cache" . DS));
     $loader->add_path(BACBOX_LIB . DS . 'models');
     $loader->add_path(BACBOX_LIB . DS . 'migrations');
     $loader->add_path(BACBOX_SRC);
     $loader->register();
     Registry::set('loader', $loader);
     // init basic configuration tokens to gain database-access
     Config::init();
     // establish database link
     ORM::configure('mysql:host=' . Config::get('mysql.host') . ';dbname=' . Config::get('mysql.database'));
     ORM::configure('username', Config::get('mysql.user'));
     ORM::configure('password', Config::get('mysql.pass'));
     ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
     ORM::configure('logging', true);
     // load remaining configuration tokens from database or cache
     Config::load();
     // execute database migrations if .autoMigrate = true
     Config::get('migrations.autoMigrate') ? Migrator::run() : null;
     // initialize and register request helper
     Registry::set('Request', $request = new Request());
     // run core controller to pre-process the user's request
     Controller::run();
     // run site migrations
     if (Registry::get('site')->site_auto_migrate) {
         SiteMigrator::run();
     }
     // initialize hooks subsystem
     Hooks::init();
     Hooks::run('core.hooks.initialized');
     // run config overrides in case the site specifies any
     Config::run_config_overrides();
     // initialize and register session handler
     Registry::set('Session', new Session());
     // initialize localization subsystem
     Registry::set('Localization', new Localization());
     // run the user's request
     Hooks::run('core.response.before');
     Registry::set('Response', $response = Dispatcher::run($request));
     Hooks::run('core.response.after');
     // send the response
     $response->send();
     // that's it, folks
     exit;
 }