1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaraComponents\Seo; |
4
|
|
|
|
5
|
|
|
class Meta |
6
|
|
|
{ |
7
|
|
|
protected $attributes = []; |
8
|
|
|
|
9
|
|
|
public function __construct(array $attributes = []) |
10
|
|
|
{ |
11
|
|
|
$this->setAttributes($attributes); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public static function make(array $attributes = []) |
15
|
|
|
{ |
16
|
|
|
return new self($attributes); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function setAttributes(array $attributes) |
20
|
|
|
{ |
21
|
|
|
foreach ($attributes as $key => $value) { |
22
|
|
|
$this->setAttribute($key, $value); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getAttributes() |
27
|
|
|
{ |
28
|
|
|
return $this->attributes; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function setAttribute($key, $value) |
32
|
|
|
{ |
33
|
|
|
$this->attributes[$key] = $value; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getAttribute($key) |
37
|
|
|
{ |
38
|
|
|
if (array_key_exists($key, $this->attributes)) { |
39
|
|
|
return $this->attributes[$key]; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function toString() |
44
|
|
|
{ |
45
|
|
|
if (count($this->attributes)) { |
46
|
|
|
return '<meta'.$this->getHtmlAttributes().'/>'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return ''; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function getHtmlAttributes() |
53
|
|
|
{ |
54
|
|
|
$html = []; |
55
|
|
|
foreach ($this->attributes as $key => $value) { |
56
|
|
|
$attribute = $key.'="'.e($value).'"'; |
57
|
|
|
|
58
|
|
|
if (! is_null($attribute)) { |
59
|
|
|
$html[] = $attribute; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return count($html) > 0 ? ' '.implode(' ', $html) : ''; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function __toString() |
67
|
|
|
{ |
68
|
|
|
return $this->toString(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|