/** * aelix constructor. * @param bool|false $initOnly only initialize basic functions, don't output anything (e.g. for migrations) * @throws CoreException */ public final function __construct($initOnly = false) { // register error and exception handler set_exception_handler(['\\aelix\\framework\\Aelix', 'handleException']); set_error_handler(['\\aelix\\framework\\Aelix', 'handleError'], E_ALL); // init autoloader require_once DIR_SRC . 'Autoload.php'; self::$autoloader = new Autoloader(); self::$autoloader->addNamespace('aelix\\framework', DIR_SRC); self::$autoloader->register(); // init event handling self::$eventHandler = new EventHandler(); // also use composer autoloader if necessary if (is_dir(DIR_ROOT . 'vendor') && is_file(DIR_ROOT . 'vendor' . DS . 'autoload.php')) { require_once DIR_ROOT . 'vendor' . DS . 'autoload.php'; } // module loader self::$moduleLoader = new ModuleLoader(DIR_ROOT . 'modules' . DS); self::$moduleLoader->registerNamespaces(); self::$moduleLoader->load(); Aelix::event()->dispatch('aelix.modules.load'); // load database config if (!is_file(DIR_ROOT . 'config.php')) { throw new CoreException('Could not find file ' . DIR_ROOT . 'config.php!', 0, 'Unable to find or open the config file for aelix: ' . DIR_ROOT . 'config.php'); } $config = (require_once DIR_ROOT . 'config.php'); // init DB self::$db = DatabaseFactory::initDatabase($config['database.driver'], $config['database.host'], $config['database.user'], $config['database.password'], $config['database.database'], $config['database.port']); // unset $config for security reasons unset($config); Aelix::event()->dispatch('aelix.database.init'); if ($initOnly) { // basic init is done, abort return; } // boot up configs self::$config = new Config('config'); Aelix::event()->dispatch('aelix.config.init'); // launch routes self::$router = new Router(); // make basepath configurable Aelix::event()->dispatch('aelix.router.register'); // init session self::$session = new Session(new DatabaseSessionHandler(self::$db, 'session'), self::config()->get('core.session.max_lifetime'), self::config()->get('core.session.gc_probability'), self::config()->get('core.session.cookie_lifetime'), self::config()->get('core.session.cookie_name')); Aelix::event()->dispatch('aelix.session.init'); // who's there? self::$user = self::$session->getUser(); Aelix::event()->dispatch('aelix.user.init'); // fire router $match = self::$router->matchCurrentRequest(); if ($match === false) { Aelix::event()->dispatch('aelix.router.no_route'); } else { $match->dispatch(); } Aelix::event()->dispatch('aelix.router.dispatch'); }