| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Html\Contract; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
use ipl\Html\Attribute; |
| 7 |
use ipl\Html\Attributes; |
| 8 |
|
| 9 |
/** |
| 10 |
* Representation of a html element |
| 11 |
* |
| 12 |
* @phpstan-import-type AttributeValue from Attribute |
| 13 |
* @phpstan-import-type AttributesType from Attributes |
| 14 |
*/ |
| 15 |
interface HtmlElementInterface |
| 16 |
{ |
| 17 |
/** |
| 18 |
* Get the HTML tag of the element |
| 19 |
* |
| 20 |
* @return non-empty-string |
| 21 |
*/ |
| 22 |
public function getTag(); |
| 23 |
|
| 24 |
/** |
| 25 |
* Get the attributes of the element |
| 26 |
* |
| 27 |
* @return Attributes |
| 28 |
*/ |
| 29 |
public function getAttributes(); |
| 30 |
|
| 31 |
/** |
| 32 |
* Add the given attributes to the element |
| 33 |
* |
| 34 |
* @param Attributes|AttributesType $attributes |
| 35 |
* |
| 36 |
* @return $this |
| 37 |
*/ |
| 38 |
public function addAttributes($attributes); |
| 39 |
|
| 40 |
/** |
| 41 |
* Return true if the attribute with the given name exists, false otherwise |
| 42 |
* |
| 43 |
* @param string $name |
| 44 |
* |
| 45 |
* @return bool |
| 46 |
*/ |
| 47 |
public function hasAttribute(string $name): bool; |
| 48 |
|
| 49 |
/** |
| 50 |
* Get the attribute with the given name |
| 51 |
* |
| 52 |
* If the attribute does not already exist, an empty one is automatically created and added to the attributes. |
| 53 |
* |
| 54 |
* @param string $name |
| 55 |
* |
| 56 |
* @return Attribute |
| 57 |
* |
| 58 |
* @throws InvalidArgumentException If the attribute does not yet exist and its name contains special characters |
| 59 |
*/ |
| 60 |
public function getAttribute(string $name): Attribute; |
| 61 |
|
| 62 |
/** |
| 63 |
* Set the attribute with the given name and value |
| 64 |
* |
| 65 |
* If the attribute with the given name already exists, it gets overridden. |
| 66 |
* |
| 67 |
* @param string $name The name of the attribute |
| 68 |
* @param AttributeValue $value The value of the attribute |
| 69 |
* |
| 70 |
* @return $this |
| 71 |
*/ |
| 72 |
public function setAttribute($name, $value); |
| 73 |
|
| 74 |
/** |
| 75 |
* Remove the attribute with the given name or remove the given value from the attribute |
| 76 |
* |
| 77 |
* @param string $name The name of the attribute |
| 78 |
* @param AttributeValue $value The value to remove if specified |
| 79 |
* |
| 80 |
* @return ?Attribute The removed or changed attribute, if any, otherwise null |
| 81 |
*/ |
| 82 |
public function removeAttribute(string $name, $value = null): ?Attribute; |
| 83 |
|
| 84 |
/** |
| 85 |
* Get whether the element is void |
| 86 |
* |
| 87 |
* @return bool |
| 88 |
*/ |
| 89 |
public function isVoid(); |
| 90 |
} |