BaseSvg
API reference › HTML SVG › Base › BaseSvg
1 subclass
Base class for constructing <svg> elements.
Provides the shared implementation for SVG container rendering, including attribute handling, content management, and immutable updates.
Intended for SVG classes that need SVG container behavior with file-backed rendering and attribute processing.
See also: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg (BaseBlock for the base block-level implementation. SvgAttribute for supported SVG attributes.).
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attributes protected | mixed[] | HTML attributes array used by the implementing class. Default: []. | UIAwesome\ |
$content protected | string | Content string assigned to the element. Default: ''. | UIAwesome\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() final | Initializes a new tag instance. | UIAwesome\ |
__toString() | Returns the rendered tag string. | UIAwesome\ |
accesskey() | Sets the accesskey attribute. | UIAwesome\ |
addAriaAttribute() | Sets an aria-* attribute. | UIAwesome\ |
addAttribute() | Adds or updates a single HTML attribute for the element. | UIAwesome\ |
addDataAttribute() | Sets a data-* attribute. | UIAwesome\ |
addEvent() | Sets an on* event attribute. | UIAwesome\ |
ariaAttributes() | Sets multiple aria-* attributes. | UIAwesome\ |
attributes() | Adds or updates multiple HTML attributes for the element. | UIAwesome\ |
autofocus() | Sets the autofocus attribute. | UIAwesome\ |
begin() final | Starts begin/end rendering for this instance. | UIAwesome\ |
class() | Sets the class attribute. | UIAwesome\ |
clearContent() | Clears encoded and raw content without changing other component state. | UIAwesome\ |
config() | Applies application-scoped config recipes to this tag. | UIAwesome\ |
content() | Appends encoded content. | UIAwesome\ |
contentEditable() | Sets the contenteditable attribute. | UIAwesome\ |
dataAttributes() | Sets multiple data-* attributes. | UIAwesome\ |
dir() | Sets the dir attribute. | UIAwesome\ |
draggable() | Sets the draggable attribute. | UIAwesome\ |
end() static final | Ends the most recent begin/end rendering block for the current class. | UIAwesome\ |
events() | Sets multiple on* event attributes. | UIAwesome\ |
filePath() | Sets the file path for the SVG file to be rendered. | BaseSvg |
fill() | Sets the SVG fill attribute for the element. | BaseSvg |
fillOpacity() | Sets SVG fill-opacity attribute for the element. | BaseSvg |
fillRule() | Sets SVG fill-rule attribute for the element. | BaseSvg |
getAttribute() | Returns the value of a single HTML attribute. | UIAwesome\ |
getAttributes() | Overrides the attribute retrieval to filter out the title attribute. | BaseSvg |
getContent() | Retrieves the content of the SVG element, injecting a <title> element when defined. | BaseSvg |
height() | Sets the height attribute. | BaseSvg |
hidden() | Sets the hidden attribute. | UIAwesome\ |
html() | Appends trusted raw HTML content without encoding or sanitizing it. | UIAwesome\ |
id() | Sets the id attribute. | UIAwesome\ |
itemId() | Sets the itemid attribute. | UIAwesome\ |
itemProp() | Sets the itemprop attribute. | UIAwesome\ |
itemRef() | Sets the itemref attribute. | UIAwesome\ |
itemScope() | Sets the itemscope attribute. | UIAwesome\ |
itemType() | Sets the itemtype attribute. | UIAwesome\ |
lang() | Sets the lang attribute. | UIAwesome\ |
opacity() | Sets the SVG opacity attribute for the element. | BaseSvg |
preserveAspectRatio() | Sets the SVG preserveAspectRatio attribute for the element. | BaseSvg |
removeAriaAttribute() | Removes an aria-* attribute. | UIAwesome\ |
removeAttribute() | Removes a specific HTML attribute from the element. | UIAwesome\ |
removeDataAttribute() | Removes a data-* attribute. | UIAwesome\ |
removeEvent() | Removes an on* event attribute. | UIAwesome\ |
render() final | Renders the tag with lifecycle hooks. | UIAwesome\ |
replaceAttributes() | Replaces all HTML attributes for the element. | UIAwesome\ |
role() | Sets the role attribute. | UIAwesome\ |
spellcheck() | Sets the spellcheck attribute. | UIAwesome\ |
stroke() | Sets the SVG stroke attribute for the element. | BaseSvg |
strokeDashArray() | Sets the SVG stroke-dasharray attribute for the element. | BaseSvg |
strokeLineCap() | Sets the SVG stroke-linecap attribute for the element. | BaseSvg |
strokeLineJoin() | Sets the SVG stroke-linejoin attribute for the element. | BaseSvg |
strokeMiterlimit() | Sets SVG stroke-miterlimit attribute for the element. | BaseSvg |
strokeOpacity() | Sets SVG stroke-opacity attribute for the element. | BaseSvg |
strokeWidth() | Sets the SVG stroke-width attribute for the element. | BaseSvg |
style() | Sets the style attribute. | UIAwesome\ |
tabIndex() | Sets the tabindex attribute. | UIAwesome\ |
tag() static | Creates and configures a new tag instance. | UIAwesome\ |
title() | Sets the title attribute. | UIAwesome\ |
transform() | Sets the SVG transform attribute for the element. | BaseSvg |
translate() | Sets the translate attribute. | UIAwesome\ |
viewBox() | Sets the SVG viewBox attribute for the element. | BaseSvg |
width() | Sets the width attribute. | BaseSvg |
x() | Sets the SVG x attribute for the element. | BaseSvg |
xmlns() | Sets the xmlns attribute for the SVG element. | BaseSvg |
y() | Sets the SVG y attribute for the element. | BaseSvg |
afterRun() protected | Post-processes rendered output. | UIAwesome\ |
beforeRun() protected | Pre-run validation for SVG rendering. | BaseSvg |
getTag() protected abstract | Returns the tag instance representing the block element. | UIAwesome\ |
isBeginExecuted() protected | Indicates whether this instance has an open or closing operation in the current context. | UIAwesome\ |
loadDefault() protected | Returns class-level default definitions. | UIAwesome\ |
run() protected | Executes the rendering routine for the SVG element. | BaseSvg |
runBegin() protected | Returns the opening tag for begin/end rendering. | UIAwesome\ |
Method details
Section titled “Method details”filePath()
Section titled “filePath() ”public function filePath(string $value): staticSets the file path for the SVG file to be rendered.
Creates a new instance with the specified file path property value, supporting explicit assignment of SVG file paths.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string | Path to the SVG file. |
Returns
static: New instance with the updated filePath property. Usage example: $element->filePath(‘/path/to/icon.svg’);
fill()
Section titled “fill() ”public function fill(string|null $value): staticSets the SVG fill attribute for the element.
Creates a new instance with the specified fill value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Fill value (for example, ‘red’, ‘url(#gradient1)’, or null to unset). |
Returns
static: New instance with the updated fill attribute.
fillOpacity()
Section titled “fillOpacity() ”public function fillOpacity(float|int|string|null $value): staticSets SVG fill-opacity attribute for the element.
Creates a new instance with the specified fill opacity value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Fill opacity value (for example, ‘0.5’, 0.5, or null to unset). |
Returns
static: New instance with the updated fill-opacity attribute.
Throws
InvalidArgumentException: if the value is outside the allowed range (‘0’-‘1’) and notnull.
fillRule()
Section titled “fillRule() ”public function fillRule(UIAwesome\Html\Svg\Values\FillRule|string|null $value): staticSets SVG fill-rule attribute for the element.
Creates a new instance with the specified fill rule value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Fill rule value to set for the element. Accepts ‘nonzero’, ‘evenodd’, FillRule enum, or null to unset. |
Returns
static: New instance with the updated fill-rule attribute.
Throws
InvalidArgumentException: if the provided value is not a validFillRuleenum or string.
getAttributes()
Section titled “getAttributes() ”public function getAttributes(): mixed[]Overrides the attribute retrieval to filter out the title attribute.
This ensures title attribute is never rendered as a standard SVG attribute, without modifying the internal
state of the object.
Returns
mixed[]: Filtered attributes array without title attribute. Usage example: $element->getAttributes();
getContent()
Section titled “getContent() ”public function getContent(): stringRetrieves the content of the SVG element, injecting a <title> element when defined.
Overrides the base implementation to intercept the title attribute. If present, it creates a <title> element
and prepends it to the content before the remaining SVG content.
Returns
string: Combined content string with the title attribute injected. Usage example: $element->getContent();
height()
Section titled “height() ”public function height(int|string|Stringable|UnitEnum|null $value): staticSets the height attribute.
Usage example:
$element->height(200);$element->height('50%');$element->height('auto');Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int|Stringable|UnitEnum| | Height value in pixels or CSS units, or null to remove the attribute. |
Returns
static: New instance with the updated height attribute.
opacity()
Section titled “opacity() ”public function opacity(float|int|string|null $value): staticSets the SVG opacity attribute for the element.
Creates a new instance with the specified opacity value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Opacity value (for example, ‘0.5’, ‘0.75’, or null to unset). |
Returns
static: New instance with the updated opacity attribute.
Throws
InvalidArgumentException: if the value is outside the allowed range (‘0’-‘1’) and notnull.
preserveAspectRatio()
Section titled “preserveAspectRatio() ”public function preserveAspectRatio(UIAwesome\Html\Svg\Values\PreserveAspectRatio|string|null $value): staticSets the SVG preserveAspectRatio attribute for the element.
Creates a new instance with the specified preserve aspect ratio value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Preserve aspect ratio value (for example, ‘xMidYMid meet’, PreserveAspectRatio enum, or null to unset). |
Returns
static: New instance with the updated preserveAspectRatio attribute.
Throws
InvalidArgumentException: if the provided value is not a validPreserveAspectRatioenum or string.
stroke()
Section titled “stroke() ”public function stroke(string|null $value): staticSets the SVG stroke attribute for the element.
Creates a new instance with the specified stroke value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Stroke paint value (for example, ‘black’, ‘url(#gradient1)’, or null to unset). |
Returns
static: New instance with the updated stroke attribute.
strokeDashArray()
Section titled “strokeDashArray() ”public function strokeDashArray(float|int|string|null $value): staticSets the SVG stroke-dasharray attribute for the element.
Creates a new instance with the specified dash array value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Dash array value (for example, ‘5.3’, ‘4’, ‘5.3 2’, or null to unset). |
Returns
static: New instance with the updated stroke-dasharray attribute.
See also
- https://www.w3.org/TR/SVG2/painting.html#StrokeDashing (Usage example: $element->strokeDashArray(5.3); $element->strokeDashArray(4); $element->strokeDashArray(null);)
strokeLineCap()
Section titled “strokeLineCap() ”public function strokeLineCap(string|UIAwesome\Html\Svg\Values\StrokeLineCap|null $value): staticSets the SVG stroke-linecap attribute for the element.
Creates a new instance with the specified stroke line cap value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UIAwesome\| | Stroke line cap style (for example, ‘round’, StrokeLineCap enum, or null to unset). |
Returns
static: New instance with the updated stroke-linecap attribute.
Throws
InvalidArgumentException: if the provided value is not a validStrokeLineCapenum or string.
strokeLineJoin()
Section titled “strokeLineJoin() ”public function strokeLineJoin(string|UIAwesome\Html\Svg\Values\StrokeLineJoin|null $value): staticSets the SVG stroke-linejoin attribute for the element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UIAwesome\| | Stroke line join style (for example, ‘miter’, StrokeLineJoin enum, or null to unset). |
Returns
static: New instance with the updated stroke-linejoin attribute.
Throws
InvalidArgumentException: if the provided value is not a validStrokeLineJoinenum or string.
strokeMiterlimit()
Section titled “strokeMiterlimit() ”public function strokeMiterlimit(float|int|string|null $value): staticSets SVG stroke-miterlimit attribute for the element.
Creates a new instance with the specified stroke miter limit value for the rendered element.
The stroke-miterlimit attribute controls the limit on the ratio of the miter length to the stroke width. When
the limit is exceeded, the join is converted from a miter to a bevel. The value must be a number ’>= 1’.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Stroke miter limit value (for example, ‘4’, ‘10’, or null to unset). |
Returns
static: New instance with the updated stroke-miterlimit attribute.
Throws
InvalidArgumentException: if value is not a number ’>= 1’ ornull.
See also
- https://www.w3.org/TR/SVG2/painting.html#StrokeMiterlimitProperty (Usage example: $element->strokeMiterlimit(4); $element->strokeMiterlimit(null);)
strokeOpacity()
Section titled “strokeOpacity() ”public function strokeOpacity(float|int|string|null $value): staticSets SVG stroke-opacity attribute for the element.
Creates a new instance with the specified stroke opacity value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Stroke opacity value (for example, ‘0.8’, ‘0.6’, or null to unset). |
Returns
static: New instance with the updated stroke-opacity attribute.
Throws
InvalidArgumentException: if the value is outside the allowed range (‘0’-‘1’) and notnull.
strokeWidth()
Section titled “strokeWidth() ”public function strokeWidth(int|string|null $value): staticSets the SVG stroke-width attribute for the element.
Creates a new instance with the specified stroke width value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int| | Stroke width value (for example, ‘2’, ‘1.5em’, or null to unset). |
Returns
static: New instance with the updated stroke-width attribute.
transform()
Section titled “transform() ”public function transform(string|null $value): staticSets the SVG transform attribute for the element.
Creates a new instance with the specified transform value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Transform value (for example, ‘rotate(45)’, ‘scale(2)’, or null to unset). |
Returns
static: New instance with the updated transform attribute.
viewBox()
Section titled “viewBox() ”public function viewBox(string|null $value): staticSets the SVG viewBox attribute for the element.
Creates a new instance with the specified view box value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | ViewBox value (for example, ‘0 0 100 100’, or null to unset). |
Returns
static: New instance with the updated viewBox attribute.
width()
Section titled “width() ”public function width(int|string|Stringable|UnitEnum|null $value): staticSets the width attribute.
Usage example:
$element->width(400);$element->width('50%');$element->width('auto');$element->width(null);Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int|Stringable|UnitEnum| | Width value in pixels or CSS units, or null to remove the attribute. |
Returns
static: New instance with the updated width attribute.
public function x(float|int|string|null $value): staticSets the SVG x attribute for the element.
Creates a new instance with the specified x-coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | X coordinate value (for example, ‘10’, ‘10.3’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated x attribute.
xmlns()
Section titled “xmlns() ”public function xmlns(string|null $value): staticSets the xmlns attribute for the SVG element.
Creates a new instance with the specified XML namespace URI for the rendered <svg> element.
The xmlns attribute is typically used on the outermost <svg> element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | XML namespace URI. |
Returns
static: New instance with the updated xmlns attribute.
See also
- https://svgwg.org/svg2-draft/struct.html#Namespace (Usage example: $element->xmlns(‘http://www.w3.org/2000/svg’);)
public function y(float|int|string|null $value): staticSets the SVG y attribute for the element.
Creates a new instance with the specified y-coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Y coordinate value (for example, ‘20’, ‘10.3’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated y attribute.
beforeRun()
Section titled “beforeRun() ”protected function beforeRun(): boolPre-run validation for SVG rendering.
Ensures at least one source of content is provided: either the filePath property or the internal content.
Returns
bool: true when preconditions are satisfied and the parent pre-run succeeds.
Throws
InvalidArgumentException: if bothfilePathandcontentare empty.
run()
Section titled “run() ”protected function run(): stringExecutes the rendering routine for the SVG element.
If a filePath is configured the SVG content is loaded, sanitized, and injected into the current document. When
no filePath is provided the parent’s run method is used.
Returns
string: Rendered SVG string or parent’s result.