Пример #1
0
 /**
  * Add library to the application
  * 
  * @param string $library
  */
 public static function add($library)
 {
     $connected = application::get('flag.global.library.' . $library . '.connected');
     if (!$connected) {
         factory::submodule('flag.global.library.' . $library . '.submodule')->add();
         application::set('flag.global.library.' . $library . '.connected', true);
     }
 }
Пример #2
0
 /**
  * Initialize db connections, cache and session
  */
 public static function init($options = [])
 {
     // initialize mbstring
     mb_internal_encoding('UTF-8');
     mb_regex_encoding('UTF-8');
     // get flags & dependencies
     $flags = application::get('flag');
     $backend = application::get('numbers.backend', ['backend_exists' => true]);
     // processing wildcard first
     $wildcard = application::get('wildcard');
     $wildcard_keys = null;
     if (!empty($wildcard['enabled']) && !empty($wildcard['model'])) {
         $wildcard_keys = call_user_func($wildcard['model']);
         application::set(['wildcard', 'keys'], $wildcard_keys);
     }
     // initialize cryptography
     $crypt = application::get('crypt');
     if (!empty($crypt) && $backend) {
         foreach ($crypt as $crypt_link => $crypt_settings) {
             if (!empty($crypt_settings['submodule']) && !empty($crypt_settings['autoconnect'])) {
                 $crypt_object = new crypt($crypt_link, $crypt_settings['submodule'], $crypt_settings);
             }
         }
     }
     // create database connections
     $db = application::get('db');
     if (!empty($db) && $backend) {
         foreach ($db as $db_link => $db_settings) {
             if (empty($db_settings['autoconnect']) || empty($db_settings['servers']) || empty($db_settings['submodule'])) {
                 continue;
             }
             $connected = false;
             foreach ($db_settings['servers'] as $server_key => $server_values) {
                 $db_object = new db($db_link, $db_settings['submodule']);
                 // wildcards replaces
                 if (isset($wildcard_keys[$db_link])) {
                     $server_values['dbname'] = $wildcard_keys[$db_link]['dbname'];
                 }
                 // connecting
                 $server_values = array_merge2($server_values, $db_settings);
                 $db_status = $db_object->connect($server_values);
                 if ($db_status['success'] && $db_status['status']) {
                     $connected = true;
                     break;
                 }
             }
             // checking if not connected
             if (!$connected) {
                 throw new Exception('Unable to open database connection!');
             }
         }
     }
     // initialize cache
     $cache = application::get('cache');
     if (!empty($cache) && $backend) {
         foreach ($cache as $cache_link => $cache_settings) {
             if (empty($cache_settings['submodule']) || empty($cache_settings['autoconnect'])) {
                 continue;
             }
             $connected = false;
             foreach ($cache_settings['servers'] as $cache_server) {
                 $cache_object = new cache($cache_link, $cache_settings['submodule']);
                 $cache_status = $cache_object->connect($cache_server);
                 if ($cache_status['success']) {
                     $connected = true;
                     break;
                 }
             }
             // checking if not connected
             if (!$connected) {
                 throw new Exception('Unable to open cache connection!');
             }
         }
     }
     // if we are from command line we exit here
     if (!empty($options['__run_only_bootstrap'])) {
         return;
     }
     // initialize session
     $session = application::get('flag.global.session');
     if (!empty($session['start']) && $backend && !application::get('flag.global.__skip_session')) {
         session::start(isset($session['options']) ? $session['options'] : []);
     }
     // we need to get overrides from session and put them back to flag array
     $flags = array_merge_hard($flags, session::get('numbers.flag'));
     application::set('flag', $flags);
     // initialize i18n
     if ($backend) {
         $temp_result = i18n::init();
         if (!$temp_result['success']) {
             throw new Exception('Could not initialize i18n.');
         }
     }
     // format
     format::init();
     // including libraries that we need to auto include
     if (!empty($flags['global']['library'])) {
         foreach ($flags['global']['library'] as $k => $v) {
             // we need to skip certain keys
             if ($k == 'submodule' || $k == 'options') {
                 continue;
             }
             // we only include if autoconnect is on
             if (!empty($v['autoconnect'])) {
                 factory::submodule('flag.global.library.' . $k . '.submodule')->add();
             }
         }
     }
     // check if we need to include system files from frontend
     if (application::get('dep.submodule.numbers.frontend.system')) {
         numbers_frontend_system_model_base::start();
     }
 }
Пример #3
0
 /**
  * Set variable into i18n
  *
  * @param string $variable
  * @param mixed $value
  */
 public static function set($variable, $value)
 {
     return factory::submodule('flag.global.i18n.submodule')->set($variable, $value);
 }