本文整理汇总了PHP中Hash::mergeDiff方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::mergeDiff方法的具体用法?PHP Hash::mergeDiff怎么用?PHP Hash::mergeDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::mergeDiff方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __setParams
/**
* Sets parameters
*
* @param array $params
*/
private function __setParams($params)
{
$defaultParams = Configure::read('ExcludeSimilarDocs');
$defaultParamsType = $defaultParams['types'][$params['type']];
$this->_params = Hash::mergeDiff($params, $defaultParamsType);
if (isset($this->_params['allowSimilarity']) && $this->_params['allowSimilarity'] > 100) {
$this->_params['allowSimilarity'] = $defaultParamsType['allowSimilarity'];
}
if (isset($this->_params['length']) && empty($this->_params['length'])) {
$this->_params['length'] = $defaultParamsType['length'];
}
}
示例2: admin_index
/**
* List of widgets
*/
public function admin_index()
{
if ($this->request->is('ajax')) {
$option_name = Configure::read('template') . '.widgets';
$widgets_db = unserialize(Configure::read(Configure::read('template') . '.widgets'));
//Before save sidebar widgets remove exist sidebar data in database.
foreach (Configure::read('sidebars') as $id => $sidebar) {
if (array_key_exists($id, $this->request->data)) {
unset($widgets_db[$id]);
}
}
$wg = array();
foreach ($this->request->data as $sidebar_id => $widgets) {
foreach ($widgets as $widget) {
foreach ($widget as $widget_id => $widget_data) {
$wg[$sidebar_id][$widget_id] = Hash::combine($widget_data, '{n}.name', '{n}.value');
}
}
}
$widgets_order = serialize(Hash::mergeDiff($wg, $widgets_db));
$this->Option->write($option_name, $widgets_order);
}
}
示例3: _bindTextDomain
/**
* Binds the given domain to a file in the specified directory.
*
* @param string $domain Domain to bind
* @return string Domain binded
*/
protected function _bindTextDomain($domain)
{
$this->_noLocale = true;
$core = true;
$merge = array();
$searchPaths = App::path('locales');
$plugins = CakePlugin::loaded();
if (!empty($plugins)) {
foreach ($plugins as $plugin) {
$pluginDomain = Inflector::underscore($plugin);
if ($pluginDomain === $domain) {
$searchPaths[] = CakePlugin::path($plugin) . 'Locale' . DS;
$searchPaths = array_reverse($searchPaths);
break;
}
}
}
foreach ($searchPaths as $directory) {
foreach ($this->l10n->languagePath as $lang) {
$localeDef = $directory . $lang . DS . $this->category;
if (is_file($localeDef)) {
$definitions = self::loadLocaleDefinition($localeDef);
if ($definitions !== false) {
$this->_domains[$domain][$this->_lang][$this->category] = $definitions;
$this->_noLocale = false;
return $domain;
}
}
if ($core) {
$app = $directory . $lang . DS . $this->category . DS . 'core';
$translations = false;
if (is_file($app . '.mo')) {
$translations = self::loadMo($app . '.mo');
}
if ($translations === false && is_file($app . '.po')) {
$translations = self::loadPo($app . '.po');
}
if ($translations !== false) {
$this->_domains[$domain][$this->_lang][$this->category] = $translations;
$merge[$domain][$this->_lang][$this->category] = $this->_domains[$domain][$this->_lang][$this->category];
$this->_noLocale = false;
$core = null;
}
}
$file = $directory . $lang . DS . $this->category . DS . $domain;
$translations = false;
if (is_file($file . '.mo')) {
$translations = self::loadMo($file . '.mo');
}
if ($translations === false && is_file($file . '.po')) {
$translations = self::loadPo($file . '.po');
}
if ($translations !== false) {
$this->_domains[$domain][$this->_lang][$this->category] = $translations;
$this->_noLocale = false;
break 2;
}
}
}
if (empty($this->_domains[$domain][$this->_lang][$this->category])) {
$this->_domains[$domain][$this->_lang][$this->category] = array();
return $domain;
}
if (isset($this->_domains[$domain][$this->_lang][$this->category][""])) {
$head = $this->_domains[$domain][$this->_lang][$this->category][""];
foreach (explode("\n", $head) as $line) {
$header = strtok($line, ':');
$line = trim(strtok("\n"));
$this->_domains[$domain][$this->_lang][$this->category]["%po-header"][strtolower($header)] = $line;
}
if (isset($this->_domains[$domain][$this->_lang][$this->category]["%po-header"]["plural-forms"])) {
$switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->_domains[$domain][$this->_lang][$this->category]["%po-header"]["plural-forms"]);
$this->_domains[$domain][$this->_lang][$this->category]["%plural-c"] = $switch;
unset($this->_domains[$domain][$this->_lang][$this->category]["%po-header"]);
}
$this->_domains = Hash::mergeDiff($this->_domains, $merge);
if (isset($this->_domains[$domain][$this->_lang][$this->category][null])) {
unset($this->_domains[$domain][$this->_lang][$this->category][null]);
}
}
return $domain;
}
示例4: _mergeHasMany
/**
* Merge the results of 'hasMany' associations.
*
* Note: this function also deals with the formatting of the data.
*
* @param array &$resultSet Data to merge into.
* @param array $assocResultSet Data to merge.
* @param string $association Name of Model being merged.
* @param Model $Model Model being merged onto.
* @return void
*/
protected function _mergeHasMany(&$resultSet, $assocResultSet, $association, Model $Model)
{
$modelAlias = $Model->alias;
$primaryKey = $Model->primaryKey;
$foreignKey = $Model->hasMany[$association]['foreignKey'];
foreach ($resultSet as &$result) {
if (!isset($result[$modelAlias])) {
continue;
}
$resultPrimaryKey = $result[$modelAlias][$primaryKey];
$merged = array();
foreach ($assocResultSet as $data) {
if ($resultPrimaryKey !== $data[$association][$foreignKey]) {
continue;
}
if (count($data) > 1) {
$data = array_merge($data[$association], $data);
unset($data[$association]);
foreach ($data as $key => $name) {
if (is_numeric($key)) {
$data[$association][] = $name;
unset($data[$key]);
}
}
$merged[] = $data;
} else {
$merged[] = $data[$association];
}
}
$result = Hash::mergeDiff($result, array($association => $merged));
}
}
示例5: testMergeDiff
/**
* testMergeDiff method
*
* @return void
*/
public function testMergeDiff()
{
$first = array('ModelOne' => array('id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2'));
$second = array('ModelTwo' => array('id' => 1002, 'field_one' => 'a2.m2.f1', 'field_two' => 'a2.m2.f2'));
$result = Hash::mergeDiff($first, $second);
$this->assertEquals($result, $first + $second);
$result = Hash::mergeDiff($first, array());
$this->assertEquals($result, $first);
$result = Hash::mergeDiff(array(), $first);
$this->assertEquals($result, $first);
$third = array('ModelOne' => array('id' => 1003, 'field_one' => 'a3.m1.f1', 'field_two' => 'a3.m1.f2', 'field_three' => 'a3.m1.f3'));
$result = Hash::mergeDiff($first, $third);
$expected = array('ModelOne' => array('id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2', 'field_three' => 'a3.m1.f3'));
$this->assertEquals($expected, $result);
$first = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2')));
$second = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's2.0.m1.f1', 'field_two' => 's2.0.m1.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's2.1.m2.f2', 'field_two' => 's2.1.m2.f2')));
$result = Hash::mergeDiff($first, $second);
$this->assertEquals($result, $first);
$third = array(0 => array('ModelThree' => array('id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2')));
$result = Hash::mergeDiff($first, $third);
$expected = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2'), 'ModelThree' => array('id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2')));
$this->assertEquals($expected, $result);
$result = Hash::mergeDiff($first, null);
$this->assertEquals($result, $first);
$result = Hash::mergeDiff($first, $second);
$this->assertEquals($result, $first + $second);
}
示例6: array
<?php
/**
* Author: samokspv <samokspv@yandex.ru>
* Date: 01.03.2014
* Time: 15:00:00
* Format: http://book.cakephp.org/2.0/en/views.html
*/
CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => true));
include 'defaultConfig.php';
$config = Hash::mergeDiff((array) Configure::read('PdfGenerator'), $defaultConfig);
Configure::write('PdfGenerator', $config);
示例7: _mergeHasMany
/**
* Merge the results of 'hasMany' associations.
*
* Note: this function also deals with the formatting of the data.
*
* @param array &$resultSet Data to merge into.
* @param array $assocResultSet Data to merge.
* @param string $association Name of Model being merged.
* @param Model $Model Model being merged onto.
* @return void
*/
protected function _mergeHasMany(&$resultSet, $assocResultSet, $association, Model $Model)
{
$modelAlias = $Model->alias;
$primaryKey = $Model->primaryKey;
$foreignKey = $Model->hasMany[$association]['foreignKey'];
// Make one pass through children and collect by parent key
// Make second pass through parents and associate children
$mergedByFK = array();
foreach ($assocResultSet as $data) {
$fk = $data[$association][$foreignKey];
if (!array_key_exists($fk, $mergedByFK)) {
$mergedByFK[$fk] = array();
}
if (count($data) > 1) {
$data = array_merge($data[$association], $data);
unset($data[$association]);
foreach ($data as $key => $name) {
if (is_numeric($key)) {
$data[$association][] = $name;
unset($data[$key]);
}
}
$mergedByFK[$fk][] = $data;
} else {
$mergedByFK[$fk][] = $data[$association];
}
}
foreach ($resultSet as &$result) {
if (!isset($result[$modelAlias])) {
continue;
}
$merged = array();
$pk = $result[$modelAlias][$primaryKey];
if (isset($mergedByFK[$pk])) {
$merged = $mergedByFK[$pk];
}
$result = Hash::mergeDiff($result, array($association => $merged));
}
}
示例8: array
<?php
/**
* Author: samokspv <samokspv@yandex.ru>
* Date: 29.10.2014
* Time: 15:00:00
*/
CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => false));
include 'defaultConfig.php';
$config = Hash::mergeDiff((array) Configure::read('ExcludeSimilarDocs'), $defaultConfig);
Configure::write('ExcludeSimilarDocs', $config);
示例9: _checkAuth
protected function _checkAuth()
{
/*
if (!$this->Auth->loggedIn()) {
return $this->redirect('/');
}
*/
//restore user session from cookie
if (!$this->Auth->loggedIn() && ($userLogin = $this->Cookie->read('User'))) {
$this->currUser = $this->User->findByUsername($userLogin['username']);
if (isset($this->currUser['User']['id'])) {
$this->Auth->login($this->currUser['User']);
}
}
$this->_addStatistic();
if ($this->Auth->loggedIn()) {
$this->loadModel('Group');
$this->currUserID = $this->Auth->user('id');
if (empty($this->currUser)) {
$this->currUser = $this->User->findById($this->currUserID);
}
$this->_initTimezone($this->currUser['User']['timezone']);
$this->_initLang($this->currUser['User']['lang']);
$conditions = array('Group.owner_id' => $this->currUserID);
$this->userGroups = $this->Group->find('all', compact('conditions', 'order'));
$groupDreamInfo = Hash::combine($this->userGroups, '{n}.Group.id', '{n}.Group.is_dream');
$this->userGroups = Hash::combine($this->userGroups, '{n}.Group.id', '{n}.Group.title');
$ids = Hash::combine($this->userGroups, '{n}.Group.id');
$conditions = array('GroupMember.approved' => '1', 'GroupMember.is_deleted' => '0', 'GroupMember.user_id' => $this->currUserID);
$groups = $this->userGroups;
$member = $this->GroupMember->find('all', compact('conditions', 'order'));
$groupDreamInfoMembers = Hash::combine($member, '{n}.Group.id', '{n}.Group.is_dream');
$member = Hash::combine($member, '{n}.Group.id', '{n}.Group.title');
$this->userGroups = Hash::mergeDiff($member, $groups);
$groupDreamInfo = Hash::mergeDiff($groupDreamInfo, $groupDreamInfoMembers);
$this->userGroups['create'] = __('Create group');
if (isset($_COOKIE['Group'])) {
$this->set('groupHeader', $this->Group->findById($_COOKIE['Group']));
}
$conditions = array('GroupMember.is_invited' => '1', 'GroupMember.is_deleted' => '0', 'GroupMember.user_id' => $this->currUserID);
$ids = $this->GroupMember->find('all', compact('conditions'));
$ids = Hash::extract($ids, '{n}.GroupMember.group_id');
$conditions = array('Group.id' => $ids);
$invites['Groups'] = $this->Group->find('all', compact('conditions', 'order'));
$this->set('invites', $invites);
$this->set('currUser', $this->currUser);
$this->set('currUserID', $this->currUserID);
$this->set('pageTitle', $this->pageTitle);
$this->set('userGroups', $this->userGroups);
$this->set(compact('groupDreamInfo'));
} else {
$this->_initLang();
}
}
示例10: array
<?php
/**
* Author: imsamurai <im.samuray@gmail.com>
* Date: 23.07.2014
* Time: 16:42:21
* Format: http://book.cakephp.org/2.0/en/views.html
*/
Configure::write('Pagination.pages', Configure::read('Pagination.pages') ? Configure::read('Pagination.pages') : 10);
$config = Hash::mergeDiff((array) Configure::read('Monitoring'), array('dateFormat' => 'H:i:s d.m.Y', 'dbDateFormat' => 'Y-m-d H:i:s', 'checkersPath' => 'Lib/Monitoring', 'defaults' => array('cron' => '*/5 * * * *', 'timeout' => 600, 'active' => false, 'priority' => 0), 'email' => array('enabled' => array('fail' => true, 'stillFail' => true, 'success' => false, 'backToNormal' => true), 'config' => 'default', 'subject' => array('fail' => 'Monitoring: %s is fail!', 'stillFail' => 'Monitoring: %s still failing!', 'success' => 'Monitoring: %s is ok!', 'backToNormal' => 'Monitoring: %s back to normal!')), 'views' => array('pluginFirst' => false), 'checkers' => array('MonitoringSelfFailCheck' => array('defaults' => array('errorText' => 'MonitoringSelfFailCheck error text'))), 'sms' => array('enabled' => array('fail' => true, 'stillFail' => true, 'success' => false, 'backToNormal' => false), 'subject' => array('fail' => 'Monitoring: %s is fail!', 'stillFail' => 'Monitoring: %s still failing!', 'success' => 'Monitoring: %s is ok!', 'backToNormal' => 'Monitoring: %s back to normal!'), 'source' => null, 'desc' => 'Monitoring')));
Configure::write('Monitoring', $config);