本文整理汇总了PHP中Q_Config::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Q_Config::merge方法的具体用法?PHP Q_Config::merge怎么用?PHP Q_Config::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q_Config
的用法示例。
在下文中一共展示了Q_Config::merge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: configure
/**
* Loads the configuration and plugins in the right order
* @method configure
* @static
* @param boolean [$force_reload=false] If true, forces the reload of the cache.
* Otherwise it happens only if Q/configServer/interval seconds
* have passed since the last time.
* @throws {Q_Exception_MissingPlugin}
*/
static function configure($force_reload = false)
{
$app_tree = new Q_Tree();
// check if config need to be reloaded
if (Q_Cache::connected()) {
// we need to know reload interval
$app_tree->load('config/Q.json');
$app_tree->load('config/app.json');
$app_tree->load('local/app.json');
$config_files = $app_tree->get('Q', 'configFiles', array());
foreach ($config_files as $cf) {
$app_tree->merge(Q_Config::getFromServer($cf));
}
// second round to catch configFiles inside configFiles
$config_files = $app_tree->get('Q', 'configFiles', array());
foreach ($config_files as $cf) {
$app_tree->merge(Q_Config::getFromServer($cf));
}
$interval = $app_tree->get('Q', 'configServer', 'interval', 60);
// reload each minute by default
$app_tree->clear(null);
$timestamp = Q_Cache::get("Q_Config\tupdate_time");
if (!isset($timestamp) || time() - $timestamp > $interval) {
$force_reload = true;
}
}
if ($force_reload) {
$old_setting = Q_Cache::ignore(true);
}
Q_Config::clear(null);
// clear the config
Q_Config::load('config/Q.json');
// Get the app config, but don't load it yet
$app_tree->load('config/app.json');
$app_tree->load('local/app.json');
// Load all the plugin config files first
$paths = explode(PS, get_include_path());
$plugins = $app_tree->get('Q', 'plugins', array());
if (!in_array('Q', $plugins)) {
array_unshift($plugins, 'Q');
}
global $Q_Bootstrap_config_plugin_limit;
$i = 0;
foreach ($plugins as $k => $v) {
++$i;
if (isset($Q_Bootstrap_config_plugin_limit) and $i > $Q_Bootstrap_config_plugin_limit) {
continue;
}
$plugin = is_numeric($k) ? $v : $k;
$plugin_path = Q::realPath('plugins' . DS . $v);
if (!$plugin_path) {
throw new Q_Exception_MissingPlugin(compact('plugin'));
}
Q_Config::load($plugin_path . DS . 'config' . DS . 'plugin.json');
array_splice($paths, 1, 0, array($plugin_path));
$PLUGIN = strtoupper($plugin);
if (!defined($PLUGIN . '_PLUGIN_DIR')) {
define($PLUGIN . '_PLUGIN_DIR', $plugin_path);
}
if (!defined($PLUGIN . '_PLUGIN_CONFIG_DIR')) {
define($PLUGIN . '_PLUGIN_CONFIG_DIR', $plugin_path . DS . 'config');
}
if (!defined($PLUGIN . '_PLUGIN_CLASSES_DIR')) {
define($PLUGIN . '_PLUGIN_CLASSES_DIR', $plugin_path . DS . 'classes');
}
if (!defined($PLUGIN . '_PLUGIN_FILES_DIR')) {
define($PLUGIN . '_PLUGIN_FILES_DIR', $plugin_path . DS . 'files');
}
if (!defined($PLUGIN . '_PLUGIN_HANDLERS_DIR')) {
define($PLUGIN . '_PLUGIN_HANDLERS_DIR', $plugin_path . DS . 'handlers');
}
if (!defined($PLUGIN . '_PLUGIN_PLUGINS_DIR')) {
define($PLUGIN . '_PLUGIN_PLUGINS_DIR', $plugin_path . DS . 'plugins');
}
if (!defined($PLUGIN . '_PLUGIN_SCRIPTS_DIR')) {
define($PLUGIN . '_PLUGIN_SCRIPTS_DIR', $plugin_path . DS . 'scripts');
}
if (!defined($PLUGIN . '_PLUGIN_VIEWS_DIR')) {
define($PLUGIN . '_PLUGIN_VIEWS_DIR', $plugin_path . DS . 'views');
}
if (!defined($PLUGIN . '_PLUGIN_TESTS_DIR')) {
define($PLUGIN . '_PLUGIN_TESTS_DIR', $plugin_path . DS . 'tests');
}
if (!defined($PLUGIN . '_PLUGIN_WEB_DIR')) {
define($PLUGIN . '_PLUGIN_WEB_DIR', $plugin_path . DS . 'web');
}
self::$plugins[$plugin] = $plugin_path;
}
$paths = array_unique($paths);
set_include_path(implode(PS, $paths));
// Now, we can merge in our app's config
//.........这里部分代码省略.........
示例2: split
//.........这里部分代码省略.........
if ($node = $config->get('node', null)) {
$nodeInternal = Q_Config::expect('Q', 'nodeInternal');
$node = array("http://{$nodeInternal['host']}:{$nodeInternal['port']}/Q_Utils/query", $node);
}
// now we shall distinguish if table is already sharded or not
if ($shard === false) {
if (!($fields = $config->get('fields', false))) {
echo "To start sharding you shall define 'fields' parameter\n";
return false;
}
}
// weather provided split config is mapped or not
$split_mapped = array_keys($parts) !== range(0, count($parts) - 1);
// set up config for shards if it does not exist yet
if ($shard === false) {
$partition = array();
foreach ($fields as $name => $hash) {
if (empty($hash)) {
$hash = 'md5';
}
$part = explode('%', $hash);
$hash = $part[0];
$len = isset($part[1]) ? $part[1] : Db_Query::HASH_LEN;
// "0" has the lowest ascii code for both md5 and normalize
// $partition[] = $hash === 'md5' ? str_pad('', $len, "0", STR_PAD_LEFT) : str_pad('', $len, " ", STR_PAD_LEFT);
$partition[] = str_pad('', $len, "0", STR_PAD_LEFT);
}
$shard = join('.', $partition);
if (Q_Config::get('Db', 'connections', $connection, 'indexes', $table, false)) {
echo "Shards are not defined but indexes for table '{$table}' are defined in local config\n";
return false;
}
// Let's merge in dummy shards section - shard with name '' is handled as single table
Q_Config::merge(array('Db' => array('connections' => array($connection => array("shards" => array(), "indexes" => array($table => array("fields" => $fields, "partition" => $split_mapped ? array($shard => '') : array($shard))))))));
$shard_name = '';
}
// get partition information
if (!($partition = Q_Config::get('Db', 'connections', $connection, 'indexes', $table, 'partition', false))) {
echo "Upps, cannot get shards partitioning\n";
return false;
}
// weather main config is mapped or not
// also $points contains the partitioning array without mapping
$points = ($mapped = array_keys($partition) !== range(0, count($partition) - 1)) ? array_keys($partition) : $partition;
$i = array_search($shard, $points);
$next = isset($points[++$i]) ? $points[$i] : null;
$fields = Q_Config::expect('Db', 'connections', $connection, 'indexes', $table, 'fields');
// now $shard and $next contain boundaries for data to split
// $points contain partitioning array without mapping - array
// $parts contains split parts (shards) definition - array or object ($split_mapped)
// $partition contains current partitioning - array or object ($mapped)
// $fields contains field names and hashes
// time to calculate new split point(s)
if (!isset($shard_name)) {
$shard_name = $mapped ? $partition[$shard] : $shard;
}
$shard_db = $class::db();
$pdo = $shard_db->reallyConnect($shard_name);
$shard_table = $class::table();
$shard_table = str_replace('{$dbname}', $shard_db->dbname, $shard_table);
$shard_table = str_replace('{$prefix}', $shard_db->prefix, $shard_table);
// verify if current shard is updated to latest version
$current_version = $shard_db->select('version', "{$shard_db->prefix}Q_plugin")->where(array("plugin" => $plugin))->fetchAll(PDO::FETCH_ASSOC);
if (!empty($current_version)) {
$current_version = $current_version[0]['version'];
$version = Q_Config::get('Q', "pluginInfo", $plugin, 'version', null);