Example #1
0
 /**
  * @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;
 }
Example #2
0
 public function value(KeyValuePair $pair)
 {
     return (string) $pair->getValue();
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 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);
 }