public function testPopValue() { $array = array('key' => 'value'); $this->assertEquals('value', ArrayHelper::popValue($array, 'key')); $this->assertArrayNotHasKey('key', $array); $object = new \stdClass(); $object->key = 'value'; $this->assertEquals('value', ArrayHelper::popValue($object, 'key')); $this->assertObjectNotHasAttribute('key', $object); }
/** * @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); }