/** * 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); }
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(); }
/** * Get a specific child of the element. * * @param string $name The Element's name * * @return Element */ public function getChild($name) { // Direct fetching $child = Helpers::arrayGet($this->getChildren(), $name); if ($child) { return $child; } // Dot notation $children = explode('.', $name); if (count($children) == 1) { return Helpers::arrayGet($this->getChildren(), $children[0]); } // Recursive fetching $subject = $this; foreach ($children as $child) { if (!$subject) { return; } $subject = $subject->getChild($child); } return $subject; }
/** * 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; }