Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Meta | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| property | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| link | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| render | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Hyde\Facades; |
| 6 | |
| 7 | use Hyde\Framework\Features\Metadata\Elements\LinkElement; |
| 8 | use Hyde\Framework\Features\Metadata\Elements\MetadataElement; |
| 9 | use Hyde\Framework\Features\Metadata\Elements\OpenGraphElement; |
| 10 | use Hyde\Framework\Features\Metadata\GlobalMetadataBag; |
| 11 | |
| 12 | /** |
| 13 | * Helpers to fluently declare HTML meta elements using their object representations. |
| 14 | */ |
| 15 | class Meta |
| 16 | { |
| 17 | /** |
| 18 | * Create a new <meta> element class with the given name and content. |
| 19 | * |
| 20 | * @param string $name The meta tag's name attribute. |
| 21 | * @param string $content The content of the meta tag. |
| 22 | * |
| 23 | * @link https://www.w3schools.com/tags/tag_meta.asp |
| 24 | */ |
| 25 | public static function name(string $name, string $content): MetadataElement |
| 26 | { |
| 27 | return new MetadataElement($name, $content); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Create a new <meta> element class with the given OpenGraph property and content. |
| 32 | * |
| 33 | * @param string $property The meta tag's property attribute. The "og:" prefix is optional. |
| 34 | * @param string $content The content of the meta tag. |
| 35 | * |
| 36 | * @link https://ogp.me/ |
| 37 | */ |
| 38 | public static function property(string $property, string $content): OpenGraphElement |
| 39 | { |
| 40 | return new OpenGraphElement($property, $content); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Create a new <link> element class with the given rel and href. |
| 45 | * |
| 46 | * @param string $rel The link tag's rel attribute. |
| 47 | * @param string $href The link tag's href attribute. |
| 48 | * @param array $attr An optional key-value array of additional attributes. |
| 49 | * |
| 50 | * @link https://www.w3schools.com/tags/tag_link.asp |
| 51 | */ |
| 52 | public static function link(string $rel, string $href, array $attr = []): LinkElement |
| 53 | { |
| 54 | return new LinkElement($rel, $href, $attr); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get the global metadata bag. |
| 59 | */ |
| 60 | public static function get(): GlobalMetadataBag |
| 61 | { |
| 62 | return GlobalMetadataBag::make(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Render the global metadata bag. |
| 67 | */ |
| 68 | public static function render(): string |
| 69 | { |
| 70 | return static::get()->render(); |
| 71 | } |
| 72 | } |