0 follower

Abstract Class Yiisoft\Html\Tag\Base\Tag

InheritanceYiisoft\Html\Tag\Base\Tag
ImplementsYiisoft\Html\NoEncodeStringableInterface
SubclassesYiisoft\Html\Tag\A, Yiisoft\Html\Tag\Address, Yiisoft\Html\Tag\Article, Yiisoft\Html\Tag\Aside, Yiisoft\Html\Tag\Audio, Yiisoft\Html\Tag\B, Yiisoft\Html\Tag\Base\BooleanInputTag, Yiisoft\Html\Tag\Base\InputTag, Yiisoft\Html\Tag\Base\ListTag, Yiisoft\Html\Tag\Base\MediaTag, Yiisoft\Html\Tag\Base\NormalTag, Yiisoft\Html\Tag\Base\TableCellTag, Yiisoft\Html\Tag\Base\TableRowsContainerTag, Yiisoft\Html\Tag\Base\VoidTag, Yiisoft\Html\Tag\Body, Yiisoft\Html\Tag\Br, Yiisoft\Html\Tag\Button, Yiisoft\Html\Tag\Caption, Yiisoft\Html\Tag\Code, Yiisoft\Html\Tag\Col, Yiisoft\Html\Tag\Colgroup, Yiisoft\Html\Tag\CustomTag, Yiisoft\Html\Tag\Datalist, Yiisoft\Html\Tag\Div, Yiisoft\Html\Tag\Em, Yiisoft\Html\Tag\Fieldset, Yiisoft\Html\Tag\Footer, Yiisoft\Html\Tag\Form, Yiisoft\Html\Tag\H1, Yiisoft\Html\Tag\H2, Yiisoft\Html\Tag\H3, Yiisoft\Html\Tag\H4, Yiisoft\Html\Tag\H5, Yiisoft\Html\Tag\H6, Yiisoft\Html\Tag\Header, Yiisoft\Html\Tag\Hgroup, Yiisoft\Html\Tag\Hr, Yiisoft\Html\Tag\Html, Yiisoft\Html\Tag\I, Yiisoft\Html\Tag\Img, Yiisoft\Html\Tag\Input, Yiisoft\Html\Tag\Input\Checkbox, Yiisoft\Html\Tag\Input\Color, Yiisoft\Html\Tag\Input\File, Yiisoft\Html\Tag\Input\Radio, Yiisoft\Html\Tag\Input\Range, Yiisoft\Html\Tag\Label, Yiisoft\Html\Tag\Legend, Yiisoft\Html\Tag\Li, Yiisoft\Html\Tag\Link, Yiisoft\Html\Tag\Meta, Yiisoft\Html\Tag\Nav, Yiisoft\Html\Tag\Noscript, Yiisoft\Html\Tag\Ol, Yiisoft\Html\Tag\Optgroup, Yiisoft\Html\Tag\Option, Yiisoft\Html\Tag\P, Yiisoft\Html\Tag\Picture, Yiisoft\Html\Tag\Pre, Yiisoft\Html\Tag\Script, Yiisoft\Html\Tag\Section, Yiisoft\Html\Tag\Select, Yiisoft\Html\Tag\Small, Yiisoft\Html\Tag\Source, Yiisoft\Html\Tag\Span, Yiisoft\Html\Tag\Strong, Yiisoft\Html\Tag\Style, Yiisoft\Html\Tag\Table, Yiisoft\Html\Tag\Tbody, Yiisoft\Html\Tag\Td, Yiisoft\Html\Tag\Textarea, Yiisoft\Html\Tag\Tfoot, Yiisoft\Html\Tag\Th, Yiisoft\Html\Tag\Thead, Yiisoft\Html\Tag\Title, Yiisoft\Html\Tag\Tr, Yiisoft\Html\Tag\Track, Yiisoft\Html\Tag\Ul, Yiisoft\Html\Tag\Video

HTML tag. Base class for all tags.

Protected Properties

Hide inherited properties

Property Type Description Defined By
$attributes array Yiisoft\Html\Tag\Base\Tag

Public Methods

Hide inherited methods

Method Description Defined By
__toString() Yiisoft\Html\Tag\Base\Tag
addAttributes() Add a set of attributes to existing tag attributes. Yiisoft\Html\Tag\Base\Tag
addClass() Add one or more CSS classes to the tag. Yiisoft\Html\Tag\Base\Tag
addStyle() Add CSS styles to the tag. Yiisoft\Html\Tag\Base\Tag
attribute() Set attribute value. Yiisoft\Html\Tag\Base\Tag
attributes() Replace attributes with a new set. Yiisoft\Html\Tag\Base\Tag
class() Replace current tag CSS classes with a new set of classes. Yiisoft\Html\Tag\Base\Tag
id() Set tag ID. Yiisoft\Html\Tag\Base\Tag
removeStyle() Remove CSS styles from the tag. Yiisoft\Html\Tag\Base\Tag
render() Yiisoft\Html\Tag\Base\Tag
unionAttributes() Union attributes with a new set. Yiisoft\Html\Tag\Base\Tag

Property Details

Hide inherited properties

$attributes protected property
protected array $attributes = []

Method Details

Hide inherited methods

__toString() public method

public string __toString ( )

                final public function __toString(): string
{
    return $this->render();
}

            
addAttributes() public method

Add a set of attributes to existing tag attributes.

Same named attributes are replaced.

public Yiisoft\Html\Tag\Base\Tag addAttributes ( array $attributes )
$attributes array

Name-value set of attributes.

                final public function addAttributes(array $attributes): static
{
    $new = clone $this;
    $new->attributes = array_merge($new->attributes, $attributes);
    return $new;
}

            
addClass() public method

Add one or more CSS classes to the tag.

public Yiisoft\Html\Tag\Base\Tag addClass ( \BackedEnum|string|null $class )
$class \BackedEnum|string|null

One or many CSS classes.

                final public function addClass(BackedEnum|string|null ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->attributes, $class);
    return $new;
}

            
addStyle() public method

Add CSS styles to the tag.

See also Yiisoft\Html\Html::addCssStyle().

public Yiisoft\Html\Tag\Base\Tag addStyle ( string|string[] $style, boolean $overwrite true )
$style string|string[]

The new style string (e.g. 'width: 100px; height: 200px') or array (e.g. ['width' => '100px', 'height' => '200px']).

$overwrite boolean

Whether to overwrite existing CSS properties if the new style contain them too.

                final public function addStyle(array|string $style, bool $overwrite = true): static
{
    $new = clone $this;
    Html::addCssStyle($new->attributes, $style, $overwrite);
    return $new;
}

            
after() protected method

protected string after ( )

                protected function after(): string
{
    return '';
}

            
attribute() public method

Set attribute value.

public Yiisoft\Html\Tag\Base\Tag attribute ( string $name, mixed $value )
$name string

Name of the attribute.

$value mixed

Value of the attribute.

                final public function attribute(string $name, mixed $value): static
{
    $new = clone $this;
    $new->attributes[$name] = $value;
    return $new;
}

            
attributes() public method

Replace attributes with a new set.

public Yiisoft\Html\Tag\Base\Tag attributes ( array $attributes )
$attributes array

Name-value set of attributes.

                final public function attributes(array $attributes): static
{
    $new = clone $this;
    $new->attributes = $attributes;
    return $new;
}

            
before() protected method

protected string before ( )

                protected function before(): string
{
    return '';
}

            
class() public method

Replace current tag CSS classes with a new set of classes.

public Yiisoft\Html\Tag\Base\Tag class ( \BackedEnum|string|null $class )
$class \BackedEnum|string|null

One or many CSS classes.

                final public function class(BackedEnum|string|null ...$class): static
{
    $new = clone $this;
    unset($new->attributes['class']);
    Html::addCssClass($new->attributes, $class);
    return $new;
}

            
getName() protected abstract method

Get tag name.

protected abstract string getName ( )
return string

Tag name.

                abstract protected function getName(): string;

            
id() public method

Set tag ID.

public Yiisoft\Html\Tag\Base\Tag id ( string|null $id )
$id string|null

Tag ID.

                final public function id(?string $id): static
{
    $new = clone $this;
    $new->attributes['id'] = $id;
    return $new;
}

            
prepareAttributes() protected method

protected void prepareAttributes ( )

                protected function prepareAttributes(): void {}

            
removeStyle() public method

Remove CSS styles from the tag.

See also Yiisoft\Html\Html::removeCssStyle().

public Yiisoft\Html\Tag\Base\Tag removeStyle ( string|string[] $properties )
$properties string|string[]

The CSS properties to be removed. You may use a string if you are removing a single property.

                final public function removeStyle(string|array $properties): static
{
    $new = clone $this;
    Html::removeCssStyle($new->attributes, $properties);
    return $new;
}

            
render() public method

public string render ( )

                final public function render(): string
{
    return $this->before() . $this->renderTag() . $this->after();
}

            
renderAttributes() protected method

Render the current tag attributes.

See also Yiisoft\Html\Html::renderTagAttributes().

protected string renderAttributes ( )

                final protected function renderAttributes(): string
{
    $this->prepareAttributes();
    return Html::renderTagAttributes($this->attributes);
}

            
renderTag() protected abstract method

Render tag object into its string representation.

protected abstract string renderTag ( )
return string

String representation of a tag object.

                abstract protected function renderTag(): string;

            
unionAttributes() public method

Union attributes with a new set.

public Yiisoft\Html\Tag\Base\Tag unionAttributes ( array $attributes )
$attributes array

Name-value set of attributes.

                final public function unionAttributes(array $attributes): static
{
    $new = clone $this;
    $new->attributes += $attributes;
    return $new;
}