本文整理汇总了PHP中CMap::mergeWith方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::mergeWith方法的具体用法?PHP CMap::mergeWith怎么用?PHP CMap::mergeWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::mergeWith方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: locate
/**
*
* Locates IP information
* @param string $ip address. If null, it will locate the IP of request
*/
public function locate($ip = null)
{
if (null === $ip) {
$ip = $_SERVER['REMOTE_ADDR'];
}
$host = str_replace('{IP}', $ip, $this->_service);
$host = str_replace('{CURRENCY}', $this->_currency, $host);
$response = $this->fetch($host);
if (!is_null($response) && is_array($response)) {
$this->_data->mergeWith($response);
$this->_data->add('ip', $ip);
return true;
}
return true;
}
示例2: relations
public function relations()
{
$map = new CMap(parent::relations());
$nrelation = array('images' => array(self::HAS_MANY, 'Image', 'model_id', 'condition' => 'images.model_name = \'Category\''));
$map->mergeWith($nrelation);
return $map;
}
示例3: addFlashMessage
/**
* @param $message
// пример использования в контроллере:
// $err = array('test1','test2'); // складываем ошибки в массив // можно доделать с использовать _addError как в контроллере orders/cart если запрос через ajax
// Yii::app()->user->setFlash('messages_red', $err);
// $this->addFlashMessage($model->getErrors(),'red'); // до кучи берем ошибки модели
// Если была/были впереди ошибка/ошибки, показываем все
*/
public function addFlashMessage($message, $style = 'success')
{
$currentMessages = Yii::app()->user->getFlash('error');
if (!is_array($currentMessages)) {
$currentMessages = array($currentMessages);
}
$map = new CMap($currentMessages);
if (is_array($message)) {
foreach ($message as $mes) {
if (is_array($mes)) {
$map->mergeWith($mes);
} else {
$map->mergeWith(array($mes));
}
}
} else {
$map->mergeWith(array($message));
}
$messages = $map->toArray();
Yii::app()->user->setFlash($style, $messages);
}
示例4: mergeWith
/**
* Merges iterable data into the map.
*
* Existing elements in the map will be overwritten if their keys are the same as those in the source.
* If the merge is recursive, the following algorithm is performed:
* <ul>
* <li>the map data is saved as $a, and the source data is saved as $b;</li>
* <li>if $a and $b both have an array indexed at the same string key, the arrays will be merged using this algorithm;</li>
* <li>any integer-indexed elements in $b will be appended to $a and reindexed accordingly;</li>
* <li>any string-indexed elements in $b will overwrite elements in $a with the same index;</li>
* </ul>
*
* @param mixed $data the data to be merged with, must be an array or object implementing Traversable
* @param boolean $recursive whether the merging should be recursive.
*
* @throws CException If data is neither an array nor an iterator.
*/
public function mergeWith($data, $recursive = true)
{
if (!$this->caseSensitive && (is_array($data) || $data instanceof Traversable)) {
$d = array();
foreach ($data as $key => $value) {
$d[strtolower($key)] = $value;
}
return parent::mergeWith($d, $recursive);
}
parent::mergeWith($data, $recursive);
}
示例5: testRecursiveMergeWithTraversable
public function testRecursiveMergeWithTraversable()
{
$map = new CMap();
$obj = new ArrayObject(array('k1' => $this->item1, 'k2' => $this->item2, 'k3' => new ArrayObject(array('k4' => $this->item3))));
$map->mergeWith($obj, true);
$this->assertEquals(3, $map->getCount());
$this->assertEquals($this->item1, $map['k1']);
$this->assertEquals($this->item2, $map['k2']);
$this->assertEquals($this->item3, $map['k3']['k4']);
}
示例6: testMergeWith
public function testMergeWith()
{
$a = array('a' => 'v1', 'v2', array('2'), 'c' => array('3', 'c' => 'a'));
$b = array('v22', 'a' => 'v11', array('2'), 'c' => array('c' => '3', 'a'));
$c = array('a' => 'v11', 'v2', array('2'), 'c' => array('3', 'c' => '3', 'a'), 'v22', array('2'));
$map = new CMap($a);
$map2 = new CMap($b);
$map->mergeWith($map2);
$this->assertTrue($map->toArray() === $c);
$array = array('key2' => $this->item1, 'key3' => $this->item3);
$this->map->mergeWith($array, false);
$this->assertTrue($this->map->getCount() == 3 && $this->map['key2'] === $this->item1 && $this->map['key3'] === $this->item3);
$this->setExpectedException('CException');
$this->map->mergeWith($this, false);
}