Ejemplo n.º 1
0
 /**
  * @param array $options
  * - type, string
  * - label, string
  * - url, string|array|null
  * - options, array
  *
  * @throws InvalidOption
  *
  * @return string
  */
 public static function buttonFactory(array $options)
 {
     // todo: add tests.
     $map = [Button::TYPE_BUTTON => 'buttonTb', Button::TYPE_SUBMIT => 'submitButtonTb', Button::TYPE_RESET => 'resetButtonTb', Button::TYPE_INPUT_SUBMIT => 'submitInputTb', Button::TYPE_INPUT_RESET => 'resetInputTb', Button::TYPE_LINK => 'linkTb'];
     $type = ArrayHelper::popValue($options, 'type', 'button');
     if (!isset($map[$type])) {
         throw new InvalidOption(sprintf('Option "type" is not valid. (%s)', $type));
     }
     return static::$map[$type](ArrayHelper::popValue($options, 'label', 'Button'), $options);
 }
Ejemplo n.º 2
0
 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'));
 }