Symbol
API reference › HTML SVG › Symbol
Represents the SVG <symbol> element for reusable symbol definitions.
Provides a concrete <symbol> element implementation that returns SvgBlock::SYMBOL and provides view,
geometry, reference point, and presentation attribute methods.
The <symbol> element defines graphical template objects that can be instantiated with the <use> element.
Usage example:
use UIAwesome\Html\Svg\Symbol;
echo Symbol::tag() ->id('icon-check') ->viewBox('0 0 16 16') ->content('<path d="M2 8l4 4 8-8" />') ->render();See also: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol (BaseBlock for the base block-level implementation.).
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 details
Section titled “Method details”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’ 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.
refX()
Section titled “refX() ”public function refX(float|int|string|null $value): staticSets the SVG refX attribute for the marker element.
Creates a new instance with the specified reference x coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Reference x coordinate value (for example, ‘0’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated refX attribute.
refY()
Section titled “refY() ”public function refY(float|int|string|null $value): staticSets the SVG refY attribute for the marker element.
Creates a new instance with the specified reference y coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Reference y coordinate value (for example, ‘0’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated refY 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.
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.
getTag()
Section titled “getTag() ”protected function getTag(): BackedEnumReturns the tag enumeration for the <symbol> element.
Returns
BackedEnum: Tag enumeration instance for <symbol>. SvgBlock for valid SVG block-level tags.