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