Пример #1
0
 /**
  * Initialize the context
  * 
  * @return null
  */
 public static function initialize()
 {
     if (self::$_debug_mode) {
         self::$debug_id = uniqid();
     }
     try {
         // The time the script was loaded
         $starttime = explode(' ', microtime());
         define('NOW', (int) $starttime[1]);
         // Set up error and exception handling
         set_exception_handler(array('TBGContext', 'exceptionHandler'));
         set_error_handler(array('TBGContext', 'errorHandler'));
         error_reporting(E_ALL | E_NOTICE | E_STRICT);
         // Set the start time
         self::setLoadStart($starttime[1] + $starttime[0]);
         TBGLogging::log('Initializing Caspar framework');
         TBGLogging::log('PHP_SAPI says "' . PHP_SAPI . '"');
         TBGLogging::log('We are version "' . TBGSettings::getVersion() . '"');
         self::checkInstallMode();
         if (!is_writable(THEBUGGENIE_CORE_PATH . DIRECTORY_SEPARATOR . 'cache')) {
             throw new Exception('The cache directory is not writable. Please correct the permissions of core/cache, and try again');
         }
         if (!self::isCLI() && !ini_get('session.auto_start')) {
             self::initializeSession();
         }
         TBGCache::checkEnabled();
         if (TBGCache::isEnabled()) {
             TBGCache::setPrefix(str_replace('.', '_', TBGSettings::getVersion()));
             TBGLogging::log(TBGCache::getCacheType() == TBGCache::TYPE_APC ? 'Caching enabled: APC, filesystem' : 'Caching enabled: filesystem');
         } else {
             TBGLogging::log('No caching available');
         }
         TBGLogging::log('Loading B2DB');
         if (self::isCLI()) {
             \b2db\Core::setHTMLException(false);
         }
         \b2db\Core::initialize(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php');
         if (!\b2db\Core::isInitialized()) {
             throw new Exception("The Bug Genie seems installed, but B2DB isn't configured. This usually indicates an error with the installation. Try removing the file " . THEBUGGENIE_PATH . "installed and try again.");
         }
         if (!self::isReadySetup()) {
             \b2db\Core::setCachingEnabled(false);
         }
         TBGLogging::log('...done (Initializing B2DB)');
         if (\b2db\Core::isInitialized()) {
             TBGLogging::log('Database connection details found, connecting');
             \b2db\Core::doConnect();
             TBGLogging::log('...done (Database connection details found, connecting)');
         }
         TBGLogging::log('...done');
         TBGLogging::log('Initializing context');
         mb_internal_encoding("UTF-8");
         mb_language('uni');
         mb_http_output("UTF-8");
         TBGLogging::log('Loading scope');
         self::setScope();
         TBGLogging::log('done (loading scope)');
         if (!self::getRouting()->hasCachedRoutes()) {
             self::loadPreModuleRoutes();
         }
         if (!self::isInstallmode()) {
             self::setupCoreListeners();
             self::loadModules();
         }
         if (!self::getRouting()->hasCachedRoutes()) {
             self::loadPostModuleRoutes();
             if (!self::isInstallmode()) {
                 self::getRouting()->cacheRoutes();
             }
         } else {
             self::loadCachedRoutes();
         }
         TBGLogging::log('...done');
         TBGLogging::log('...done initializing');
         TBGLogging::log('Caspar framework loaded');
     } catch (Exception $e) {
         if (!self::isCLI() && !self::isInstallmode()) {
             throw $e;
         }
     }
 }