/** * @param string $name * @param string $title * * @throws ArgumentTypeException */ function __construct($name, $title = '') { $this->attrs = new NamedObjectList([KeyValuePair::getClass()]); $this->children = new NamedObjectList([Block::getClass(), AbstractField::getClass()]); parent::__construct($name); $this->title($title); $this->isValid = true; $this->templateName = self::DEFAULT_TEMPLATE; }
public function value(KeyValuePair $pair) { return (string) $pair->getValue(); }
/** * @param array $data * * @return KeyValuePair * @throws ArgumentException */ public static function initFromArray(array $data) { if (!isset($data['name'])) { throw new ArgumentException('Имя должно быть заполнено.'); } $pair = new KeyValuePair($data['name']); if (isset($data['value'])) { $pair->setValue((string) $data['value']); } if (isset($data['canBeShort'])) { $pair->setCanBeShort((bool) $data['canBeShort']); } return $pair; }
public function testNameComas() { $pair = new KeyValuePair(''); $pair->setNameComas('123'); $comas = $pair->getNameComas(); $this->assertEquals(['123', '123'], $comas); $pair->setNameComas('123', '321'); $comas = $pair->getNameComas(); $this->assertEquals(['123', '321'], $comas); }