/** * @param int|array $content * @param array $options * * @return string */ public static function progress($content, array $options = []) { // todo: refactor this method. if (!is_array($content)) { $content = [['percentage' => $content]]; } $defaults = ['context' => null, 'showLabel' => false]; ArrayHelper::moveValues(array('context', 'showLabel'), $options, $defaults); $content = static::listFactory(function ($bar) use($defaults) { $bar = static::getRenderer()->normalizeElement($bar); ArrayHelper::copyValues(array_keys($defaults), $bar, $bar['options']); ArrayHelper::defaultValues($bar['options'], $defaults); return static::progressBar($bar['percentage'], $bar['options']); }, $content); if (ArrayHelper::popValue($options, 'animated')) { static::addCssClass($options, 'active'); $options['striped'] = true; // active must be striped. } static::addCssClass($options, 'progress'); static::addCssClassWithCondition($options, 'progress-striped', ArrayHelper::popValue($options, 'striped')); return static::tag(ArrayHelper::popValue($options, 'tag', 'div'), $content, $options); }
public function testMoveValues() { $a = array('key' => 'iron', 'door' => 'wooden'); $b = array(); ArrayHelper::moveValues(array('key', 'door'), $a, $b); $this->assertArrayNotHasKey('key', $a); $this->assertArrayNotHasKey('door', $a); $this->assertEquals('iron', ArrayHelper::getValue($b, 'key')); $this->assertEquals('wooden', ArrayHelper::getValue($b, 'door')); $a = array('key' => 'iron', 'door' => 'wooden'); $b = array('key' => 'steel', 'door' => 'glass'); ArrayHelper::moveValues(array('key', 'door'), $a, $b, true); $this->assertEquals('iron', ArrayHelper::getValue($b, 'key')); $this->assertEquals('wooden', ArrayHelper::getValue($b, 'door')); }