本文整理汇总了PHP中format::init方法的典型用法代码示例。如果您正苦于以下问题:PHP format::init方法的具体用法?PHP format::init怎么用?PHP format::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类format
的用法示例。
在下文中一共展示了format::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* 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'])) {
//.........这里部分代码省略.........