src/Tag.php
public function add($tag, ...$arguments)
    {
        $tag = strtolower($tag);
        $text = '';
        $attributes = [];

        for ($i = 0; $i <= 1; $i++) {
            if (array_has($arguments, $i)) {
                if (is_array(array_get($arguments, $i))) {
                    $attributes = array_get($arguments, $i);
                } elseif (is_string(array_get($arguments, $i)) || is_object(array_get($arguments, $i))) {
                    $text = array_get($arguments, $i);
                }
            }
        }

        if ($this->tag === 'tag'
            || empty($this->allowed_tags)
            || in_array($tag, $this->allowed_tags)
            || in_array($tag, self::$special_tags)) {

            // Tag belongs to the special tags list.
            if (in_array($tag, self::$special_tags)) {
                $tag_object = Html::createElement($tag, $text, $attributes);
                $tag_object->text($text)->addAttributes($attributes);
                self::$tag_registry[] = &$tag_object;
                $this->child_nodes[] = &$tag_object;

                return $tag_object;
            }

            // Create the class name for this tag
            $class_name = 'Bluora\\LaravelHtmlBuilder\\Tag\\'.ucfirst($tag);

            // If the tag exists, otherwise we throw an exception.
            if (class_exists($class_name)) {
                $tag_object = (new $class_name())
                    ->setAttributes($attributes)
                    ->setText($text);
                self::$tag_registry[] = &$tag_object;
                $this->child_nodes[] = &$tag_object;
                $tag_object->setParent($tag_object);

                return $tag_object;
            }

            throw new \Exception($tag.' does not exist.');
        }

        throw new \Exception($this->tag.' does permit '.$tag);
    }
public function add($tag, ...$arguments)
    {
        $tag = strtolower($tag);
        $text = '';
        $attributes = [];

        for ($i = 0; $i <= 1; $i++) {
            if (array_has($arguments, $i)) {
                if (is_array(array_get($arguments, $i))) {
                    $attributes = array_get($arguments, $i);
                } elseif (is_string(array_get($arguments, $i)) || is_object(array_get($arguments, $i))) {
                    $text = array_get($arguments, $i);
                }
            }
        }

        if ($this->tag === 'tag'
            || empty($this->allowed_tags)
            || in_array($tag, $this->allowed_tags)
            || in_array($tag, self::$special_tags)) {

            // Tag belongs to the special tags list.
            if (in_array($tag, self::$special_tags)) {
                $tag_object = Html::createElement($tag, $text, $attributes);
                $tag_object->text($text)->addAttributes($attributes);
                self::$tag_registry[] = &$tag_object;
                $this->child_nodes[] = &$tag_object;

                return $tag_object;
            }

            // Create the class name for this tag
            $class_name = 'Bluora\\LaravelHtmlBuilder\\Tag\\'.ucfirst($tag);

            // If the tag exists, otherwise we throw an exception.
            if (class_exists($class_name)) {
                $tag_object = (new $class_name())
                    ->setAttributes($attributes)
                    ->setText($text);
                self::$tag_registry[] = &$tag_object;
                $this->child_nodes[] = &$tag_object;
                $tag_object->setParent($tag_object);

                return $tag_object;
            }

            throw new \Exception($tag.' does not exist.');
        }

        throw new \Exception($this->tag.' does permit '.$tag);
    }
public function add ( $ tag , ... $ arguments ) { $ tag = strtolower ( $ tag ) ; $ text = '' ; $ attributes = [ ] ; for ( $ i = 0 ; $ i <= 1 ; $ i ++ ) { if ( array_has ( $ arguments , $ i ) ) { if ( is_array ( array_get ( $ arguments , $ i ) ) ) { $ attributes = array_get ( $ arguments , $ i ) ; } elseif ( is_string ( array_get ( $ arguments , $ i ) ) || is_object ( array_get ( $ arguments , $ i ) ) ) { $ text = array_get ( $ arguments , $ i ) ; } } } if ( $ this -> tag === 'tag' || empty ( $ this -> allowed_tags ) || in_array ( $ tag , $ this -> allowed_tags ) || in_array ( $ tag , self :: $ special_tags ) ) { // Tag belongs to the special tags list. if ( in_array ( $ tag , self :: $ special_tags ) ) { $ tag_object = Html :: createElement ( $ tag , $ text , $ attributes ) ; $ tag_object -> text ( $ text ) -> addAttributes ( $ attributes ) ; self :: $ tag_registry [ ] = & $ tag_object ; $ this -> child_nodes [ ] = & $ tag_object ; return $ tag_object ; } // Create the class name for this tag $ class_name = 'Bluora\\LaravelHtmlBuilder\\Tag\\' . ucfirst ( $ tag ) ; // If the tag exists, otherwise we throw an exception. if ( class_exists ( $ class_name ) ) { $ tag_object = ( new $ class_name ( ) ) -> setAttributes ( $ attributes ) -> setText ( $ text ) ; self :: $ tag_registry [ ] = & $ tag_object ; $ this -> child_nodes [ ] = & $ tag_object ; $ tag_object -> setParent ( $ tag_object ) ; return $ tag_object ; } throw new \ Exception ( $ tag . ' does not exist.' ) ; } throw new \ Exception ( $ this -> tag . ' does permit ' . $ tag ) ; }
Add a child node to this tag.

@param string $tag
@param array  $arguments

@return Bluora\LaravelHtmlBuilder\Tag
Add a child node to this tag .