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