本文整理汇总了PHP中Cake\Utility\Hash::mergeDiff方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::mergeDiff方法的具体用法?PHP Hash::mergeDiff怎么用?PHP Hash::mergeDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Hash
的用法示例。
在下文中一共展示了Hash::mergeDiff方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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, array());
$this->assertEquals($result, $first);
$result = Hash::mergeDiff($first, $second);
$this->assertEquals($result, $first + $second);
}
示例2: testMergeDiff
/**
* testMergeDiff method
*
* @return void
*/
public function testMergeDiff()
{
$first = ['ModelOne' => ['id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2']];
$second = ['ModelTwo' => ['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, []);
$this->assertEquals($result, $first);
$result = Hash::mergeDiff([], $first);
$this->assertEquals($result, $first);
$third = ['ModelOne' => ['id' => 1003, 'field_one' => 'a3.m1.f1', 'field_two' => 'a3.m1.f2', 'field_three' => 'a3.m1.f3']];
$result = Hash::mergeDiff($first, $third);
$expected = ['ModelOne' => ['id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2', 'field_three' => 'a3.m1.f3']];
$this->assertEquals($expected, $result);
$first = [0 => ['ModelOne' => ['id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2']], 1 => ['ModelTwo' => ['id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2']]];
$second = [0 => ['ModelOne' => ['id' => 1001, 'field_one' => 's2.0.m1.f1', 'field_two' => 's2.0.m1.f2']], 1 => ['ModelTwo' => ['id' => 1002, 'field_one' => 's2.1.m2.f2', 'field_two' => 's2.1.m2.f2']]];
$result = Hash::mergeDiff($first, $second);
$this->assertEquals($result, $first);
$third = [0 => ['ModelThree' => ['id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2']]];
$result = Hash::mergeDiff($first, $third);
$expected = [0 => ['ModelOne' => ['id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2'], 'ModelThree' => ['id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2']], 1 => ['ModelTwo' => ['id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2']]];
$this->assertEquals($expected, $result);
$result = Hash::mergeDiff($first, []);
$this->assertEquals($result, $first);
$result = Hash::mergeDiff($first, $second);
$this->assertEquals($result, $first + $second);
}
示例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('Locale');
$plugins = Plugin::loaded();
if (!empty($plugins)) {
foreach ($plugins as $plugin) {
$pluginDomain = Inflector::underscore($plugin);
if ($pluginDomain === $domain) {
$searchPaths[] = Plugin::path($plugin) . 'Locale/';
$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 = static::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 = static::loadMo($app . '.mo');
}
if ($translations === false && is_file($app . '.po')) {
$translations = static::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 = static::loadMo($file . '.mo');
}
if ($translations === false && is_file($file . '.po')) {
$translations = static::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;
}