Ejemplo n.º 1
0
 /**
  * Dynamically create an input type
  *
  * @param string $method     The input type
  * @param array  $parameters
  *
  * @return Input
  */
 public static function __callStatic($method, $parameters)
 {
     $name = Helpers::arrayGet($parameters, 0);
     $value = Helpers::arrayGet($parameters, 1);
     $attributes = Helpers::arrayGet($parameters, 2);
     return new static($method, $name, $value, $attributes);
 }
Ejemplo n.º 2
0
 public function __construct($element = null, $value = null, $attributes = null)
 {
     switch ($element) {
         case 'img':
             $src = Helpers::arrayGet($attributes, 'src', '');
             $alt = Helpers::arrayGet($attributes, 'alt', '');
             $this->htmlObject = new \HtmlObject\Image($src, $alt, $attributes);
             break;
         case 'input':
             $type = Helpers::arrayGet($attributes, 'type', '');
             $name = Helpers::arrayGet($attributes, 'name', '');
             $this->htmlObject = new \HtmlObject\Input($type, $name, $value, $attributes);
             break;
         case 'a':
             $href = Helpers::arrayGet($attributes, 'href', '');
             $this->htmlObject = new \HtmlObject\Link($href, $value, $attributes);
             break;
         default:
             $this->htmlObject = new \HtmlObject\Element($element, $value, $attributes);
             break;
     }
     $this->updateContent();
 }
Ejemplo n.º 3
0
 /**
  * Remove one or more classes to the current field.
  *
  * @param string $classes The class(es) to remove
  *
  * @return $this
  */
 public function removeClass($classes)
 {
     if (!is_array($classes)) {
         $classes = explode(' ', $classes);
     }
     $thisClasses = explode(' ', Helpers::arrayGet($this->attributes, 'class'));
     foreach ($classes as $class) {
         $exists = array_search($class, $thisClasses);
         if (!is_null($exists)) {
             unset($thisClasses[$exists]);
         }
     }
     $this->attributes['class'] = implode(' ', $thisClasses);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Creates an Element or a TextNode from an element/value combo.
  *
  * @param string $element    The element/string
  * @param string $value      The element's content
  * @param array  $attributes
  *
  * @return Tag
  */
 protected function createTagFromString($element, $value = null, $attributes = array())
 {
     // If it's an element/value, create the element
     if (strpos($element, '<') === false && !$this->hasChild($value) && Helpers::isKnownTag($element)) {
         return new Element($element, $value, $attributes);
     }
     // Else create a text element
     if ($this->hasChild($value) || !$value) {
         return new Text($element);
     }
     return new Text($value);
 }
Ejemplo n.º 5
0
 public function testCanIgnoreNullAttributesWhenNecessary()
 {
     $attributes = array('min' => 0, 'max' => 0, 'value' => 0, 'required' => 0);
     $attributes = Helpers::parseAttributes($attributes);
     $this->assertEquals(' min="0" max="0" value="0"', $attributes);
 }