Final Class Yiisoft\Html\Tag\Script
| Inheritance | Yiisoft\Html\Tag\Script » Yiisoft\Html\Tag\Base\NormalTag » Yiisoft\Html\Tag\Base\Tag |
|---|---|
| Implements | Yiisoft\Html\NoEncodeStringableInterface |
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $attributes | array | Yiisoft\Html\Tag\Base\Tag |
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| after() | Yiisoft\Html\Tag\Script | |
| before() | Yiisoft\Html\Tag\Base\Tag | |
| generateContent() | Yiisoft\Html\Tag\Script | |
| getName() | Yiisoft\Html\Tag\Script | |
| prepareAttributes() | Yiisoft\Html\Tag\Base\Tag | |
| prepend() | Yiisoft\Html\Tag\Base\NormalTag | |
| renderAttributes() | Render the current tag attributes. | Yiisoft\Html\Tag\Base\Tag |
| renderTag() | Yiisoft\Html\Tag\Base\NormalTag |
Method Details
Defined in: Yiisoft\Html\Tag\Base\Tag::__toString()
| public string __toString ( ) |
final public function __toString(): string
{
return $this->render();
}
Defined in: Yiisoft\Html\Tag\Base\Tag::addAttributes()
Add a set of attributes to existing tag attributes.
Same named attributes are replaced.
| public Yiisoft\Html\Tag\Script 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;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::addClass()
Add one or more CSS classes to the tag.
| public Yiisoft\Html\Tag\Script 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;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::addStyle()
Add CSS styles to the tag.
See also Yiisoft\Html\Html::addCssStyle().
| public Yiisoft\Html\Tag\Script addStyle ( string|string[] $style, boolean $overwrite = true ) | ||
| $style | string|string[] |
The new style string (e.g. |
| $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;
}
| protected string after ( ) |
protected function after(): string
{
return $this->noscript !== null ? (string) $this->noscript : '';
}
| public self async ( boolean $async = true ) | ||
| $async | boolean | |
public function async(bool $async = true): self
{
$new = clone $this;
$new->attributes['async'] = $async;
return $new;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::attribute()
Set attribute value.
| public Yiisoft\Html\Tag\Script 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;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::attributes()
Replace attributes with a new set.
| public Yiisoft\Html\Tag\Script 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;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::before()
| protected string before ( ) |
protected function before(): string
{
return '';
}
| public self charset ( string|null $charset ) | ||
| $charset | string|null | |
public function charset(?string $charset): self
{
$new = clone $this;
$new->attributes['charset'] = $charset;
return $new;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::class()
Replace current tag CSS classes with a new set of classes.
| public Yiisoft\Html\Tag\Script 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;
}
Defined in: Yiisoft\Html\Tag\Base\NormalTag::close()
| public string close ( ) | ||
| return | string |
Closing tag. |
|---|---|---|
final public function close(): string
{
return '</' . $this->getName() . '>';
}
| public self content ( string $content ) | ||
| $content | string |
Tag content. |
public function content(string $content): self
{
$new = clone $this;
$new->content = $content;
return $new;
}
| public self defer ( boolean $defer = true ) | ||
| $defer | boolean | |
public function defer(bool $defer = true): self
{
$new = clone $this;
$new->attributes['defer'] = $defer;
return $new;
}
| protected string generateContent ( ) | ||
| return | string |
Obtain tag content. |
|---|---|---|
protected function generateContent(): string
{
return $this->content;
}
| public string|null getNonce ( ) |
public function getNonce(): ?string
{
$nonce = $this->attributes['nonce'] ?? null;
if (is_string($nonce) || $nonce === null) {
return $nonce;
}
throw new LogicException(
sprintf(
'Nonce should be string or null. Got %s.',
get_debug_type($nonce),
),
);
}
Defined in: Yiisoft\Html\Tag\Base\Tag::id()
Set tag ID.
| public Yiisoft\Html\Tag\Script 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;
}
| public self nonce ( string|null $nonce ) | ||
| $nonce | string|null | |
public function nonce(?string $nonce): self
{
$new = clone $this;
if ($nonce === null) {
unset($new->attributes['nonce']);
} else {
$new->attributes['nonce'] = $nonce;
}
return $new;
}
| public self noscript ( string|\Stringable|null $content ) | ||
| $content | string|\Stringable|null | |
public function noscript(string|Stringable|null $content): self
{
$new = clone $this;
$new->noscript = $content === null ? null : Noscript::tag()->content($content);
return $new;
}
| public self noscriptTag ( Yiisoft\Html\Tag\Noscript|null $noscript ) | ||
| $noscript | Yiisoft\Html\Tag\Noscript|null | |
public function noscriptTag(?Noscript $noscript): self
{
$new = clone $this;
$new->noscript = $noscript;
return $new;
}
Defined in: Yiisoft\Html\Tag\Base\NormalTag::open()
| public string open ( ) | ||
| return | string |
Opening tag. |
|---|---|---|
final public function open(): string
{
return '<' . $this->getName() . $this->renderAttributes() . '>' . $this->prepend();
}
Defined in: Yiisoft\Html\Tag\Base\Tag::prepareAttributes()
| protected void prepareAttributes ( ) |
protected function prepareAttributes(): void {}
Defined in: Yiisoft\Html\Tag\Base\NormalTag::prepend()
| protected string prepend ( ) |
protected function prepend(): string
{
return '';
}
Defined in: Yiisoft\Html\Tag\Base\Tag::removeStyle()
Remove CSS styles from the tag.
See also Yiisoft\Html\Html::removeCssStyle().
| public Yiisoft\Html\Tag\Script 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;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::render()
| public string render ( ) |
final public function render(): string
{
return $this->before() . $this->renderTag() . $this->after();
}
Defined in: Yiisoft\Html\Tag\Base\Tag::renderAttributes()
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);
}
Defined in: Yiisoft\Html\Tag\Base\NormalTag::renderTag()
| protected string renderTag ( ) |
final protected function renderTag(): string
{
return $this->open() . $this->generateContent() . $this->close();
}
| public self src ( string|null $url ) | ||
| $url | string|null | |
public function src(?string $url): self
{
$new = clone $this;
$new->attributes['src'] = $url;
return $new;
}
Defined in: Yiisoft\Html\Tag\Base\NormalTag::tag()
| public static Yiisoft\Html\Tag\Script tag ( ) |
final public static function tag(): static
{
return new static();
}
| public self type ( string|null $type ) | ||
| $type | string|null | |
public function type(?string $type): self
{
$new = clone $this;
$new->attributes['type'] = $type;
return $new;
}
Defined in: Yiisoft\Html\Tag\Base\Tag::unionAttributes()
Union attributes with a new set.
| public Yiisoft\Html\Tag\Script 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;
}
Signup or Login in order to comment.