コード例 #1
0
ファイル: ElementTest.php プロジェクト: slkxmail/App
 /**
  * @expectedException InvalidArgumentException
  */
 public function testSetAttributes()
 {
     $element = new Element('test', new \ArrayObject(array('attr' => 'attr_value')), new \ArrayObject(array('opt1' => 'value')));
     $this->assertInternalType('string', $element->getAttribute('attr'));
     $this->assertEquals('attr_value', $element->getAttribute('attr'));
     $this->assertEquals(array('name' => 'test', 'attr' => 'attr_value'), $element->getAttributes());
     $this->assertEquals(array('attr' => 'attr_value'), $element->removeAttribute('name')->getAttributes());
     $this->assertEquals(array(), $element->clearAttributes()->getAttributes());
     $this->assertEquals(array('decorator' => 'test'), $element->setDecorator('test')->getAttributes());
     $this->assertEquals(array('decorator' => 'test'), $element->removeAttributes(array('test'))->getAttributes());
     $this->assertEquals('test', $element->getDecorator());
     $this->assertEquals('', $element->removeAttribute('decorator')->getDecorator());
     $element->setAttributes(null);
 }
コード例 #2
0
ファイル: Factory.php プロジェクト: slkxmail/App
 /**
  * Configure an element based on the provided specification
  *
  * Specification can contain any of the following:
  * - type: the Element class to use; defaults to \Zend\Form\Element
  * - name: what name to provide the element, if any
  * - options: an array, Traversable, or ArrayAccess object of element options
  * - attributes: an array, Traversable, or ArrayAccess object of element
  *   attributes to assign
  *
  * @param \App\Form\Element|\App\Form\Element $element
  * @param  array|Traversable|ArrayAccess               $spec
  * @return Element
  */
 public function configureElement(Element $element, $spec)
 {
     $spec = $this->validateSpecification($spec, __METHOD__);
     $name = isset($spec['name']) ? $spec['name'] : null;
     $options = isset($spec['options']) ? $spec['options'] : null;
     $attributes = isset($spec['attributes']) ? $spec['attributes'] : null;
     if ($name !== null && $name !== '') {
         $element->setName($name);
     }
     if (is_array($options) || $options instanceof Traversable || $options instanceof ArrayAccess) {
         $element->setOptions($options);
     }
     if (is_array($attributes) || $attributes instanceof Traversable || $attributes instanceof ArrayAccess) {
         $element->setAttributes($attributes);
     }
     return $element;
 }