public function testMerge() { $a = array('this' => 'is', 'array' => 'a'); $b = array('is' => 'this', 'b' => 'array'); $array = TbArray::merge($a, $b); $this->assertEquals('is', TbArray::getValue('this', $array)); $this->assertEquals('a', TbArray::getValue('array', $array)); $this->assertEquals('this', TbArray::getValue('is', $array)); $this->assertEquals('array', TbArray::getValue('b', $array)); }
/** * Initializes the plugin options */ public function initOptions() { $options = array(); foreach (array('matcher', 'sorter', 'updater', 'highlighter') as $fn) { if ($this->{$fn} !== null) { if ($this->{$fn} instanceof CJavaScriptExpression) { $options[$fn] = $this->{$fn}; } else { $options[$fn] = new CJavaScriptExpression($this->{$fn}); } } } $this->pluginOptions = TbArray::merge(array('source' => $this->source, 'items' => $this->items, 'minLength' => $this->minLength), $options); }
/** * @inheritdoc */ public function init() { parent::init(); if (!$this->hasModel() && $this->name === null) { throw new CException("Either 'name', or 'model' and 'attribute' properties must be specified."); } if (!isset($this->htmlOptions['id'])) { $this->htmlOptions['id'] = $this->hasModel() ? CHtml::activeId($this->model, $this->attribute) : $this->getId(); } $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin')); $this->htmlOptions = TbArray::merge($this->asDataAttributes($this->pluginOptions), $this->htmlOptions); $this->pluginOptions = false; if ($this->hasModel()) { $this->htmlOptions['data-name'] = CHtml::activeId($this->model, $this->attribute); $this->htmlOptions['data-value'] = CHtml::value($this->model, $this->attribute); } else { $this->htmlOptions['data-name'] = $this->name; $this->htmlOptions['data-value'] = $this->value; } }
/** * Generates multiple media objects. * @param array $items item configurations. * @param string $tag the item tag name. * @return string generated objects. */ public static function medias(array $items, $tag = 'div') { if (!empty($items)) { $output = ''; foreach ($items as $itemOptions) { if (isset($itemOptions['visible']) && $itemOptions['visible'] === false) { continue; } // todo: consider removing the support for htmlOptions. $options = TbArray::popValue('htmlOptions', $itemOptions, array()); if (!empty($options)) { $itemOptions = TbArray::merge($options, $itemOptions); } $image = TbArray::popValue('image', $itemOptions); $heading = TbArray::popValue('heading', $itemOptions, ''); $content = TbArray::popValue('content', $itemOptions, ''); TbArray::defaultValue('tag', $tag, $itemOptions); $output .= self::media($image, $heading, $content, $itemOptions); } return $output; } return ''; }