1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\Seoable\Protocols; |
4
|
|
|
|
5
|
|
|
use MadWeb\Seoable\Fields\Meta\Canonical; |
6
|
|
|
use MadWeb\Seoable\Fields\Meta\Description; |
7
|
|
|
use MadWeb\Seoable\Fields\Meta\Keywords; |
8
|
|
|
use MadWeb\Seoable\Fields\Meta\Languages; |
9
|
|
|
use MadWeb\Seoable\Fields\Meta\MetaTag; |
10
|
|
|
use MadWeb\Seoable\Fields\Meta\Next; |
11
|
|
|
use MadWeb\Seoable\Fields\Meta\Prev; |
12
|
|
|
use MadWeb\Seoable\Fields\Meta\Title; |
13
|
|
|
use MadWeb\Seoable\Fields\Meta\TitleSeparator; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @method Meta setMetaRaw(array $value) |
17
|
|
|
* @method Meta addMetaRaw(string $meta, string $value, string $name = 'name') |
18
|
|
|
* @method Meta setTitleRaw(string $value) |
19
|
|
|
* @method Meta setTitleSeparatorRaw(string $value) |
20
|
|
|
* @method Meta setDescriptionRaw(string $value) |
21
|
|
|
* @method Meta setCanonicalRaw(string $value) |
22
|
|
|
* @method Meta setPrevRaw(string $value) |
23
|
|
|
* @method Meta setNextRaw(string $value) |
24
|
|
|
* @method Meta setKeywordsRaw(array|string $value) |
25
|
|
|
* @method Meta setLanguagesRaw(array $value) |
26
|
|
|
* @method Meta addLanguageRaw(string $lang, string $url) |
27
|
|
|
*/ |
28
|
|
|
class Meta extends Protocol |
29
|
|
|
{ |
30
|
3 |
|
public function setMeta(array $tags): self |
31
|
|
|
{ |
32
|
3 |
|
foreach ($this->parseValue($tags, MetaTag::class) as $item) { |
33
|
3 |
|
$this->metaService->addMeta(...array_values($item)); |
34
|
|
|
} |
35
|
|
|
|
36
|
3 |
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
3 |
|
public function addMeta(string $meta, string $value, string $name = 'name'): self |
40
|
|
|
{ |
41
|
3 |
|
$this->metaService->addMeta(...array_values( |
42
|
3 |
|
$this->parseValue( |
43
|
3 |
|
[compact('meta', 'value', 'name')], |
44
|
3 |
|
MetaTag::class |
45
|
3 |
|
)[0] |
46
|
|
|
)); |
47
|
|
|
|
48
|
3 |
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** @param array|string $value */ |
52
|
12 |
|
public function setTitle($value, string $templateKey = ''): self |
53
|
|
|
{ |
54
|
12 |
|
$this->seoTools->setTitle($this->parseValue( |
55
|
12 |
|
$value, |
56
|
12 |
|
$templateKey ? new Title($value, $this->model, $templateKey) : Title::class |
57
|
|
|
)); |
58
|
|
|
|
59
|
12 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** @param string $value */ |
63
|
|
|
public function setTitleSeparator(string $value): self |
64
|
|
|
{ |
65
|
|
|
$this->metaService->setTitleSeparator($this->parseValue($value, TitleSeparator::class)); |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** @param array|string $value */ |
71
|
12 |
|
public function setDescription($value, string $templateKey = ''): self |
72
|
|
|
{ |
73
|
12 |
|
$this->seoTools->setDescription($this->parseValue( |
74
|
12 |
|
$value, |
75
|
12 |
|
$templateKey ? new Description($value, $this->model, $templateKey) : Description::class |
76
|
|
|
)); |
77
|
|
|
|
78
|
12 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
3 |
|
public function setCanonical(string $value): self |
82
|
|
|
{ |
83
|
3 |
|
$this->seoTools->setCanonical($this->parseValue($value, Canonical::class)); |
84
|
|
|
|
85
|
3 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
3 |
|
public function setPrev(string $value): self |
89
|
|
|
{ |
90
|
3 |
|
$this->metaService->setPrev($this->parseValue($value, Prev::class)); |
91
|
|
|
|
92
|
3 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
3 |
|
public function setNext(string $value): self |
96
|
|
|
{ |
97
|
3 |
|
$this->metaService->setNext($this->parseValue($value, Next::class)); |
98
|
|
|
|
99
|
3 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** @param array|string $value */ |
103
|
3 |
|
public function setKeywords($value): self |
104
|
|
|
{ |
105
|
3 |
|
$this->metaService->setKeywords($this->parseValue($value, Keywords::class)); |
106
|
|
|
|
107
|
3 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
3 |
|
public function setLanguages(array $value): self |
111
|
|
|
{ |
112
|
3 |
|
$this->metaService->addAlternateLanguages($this->parseValue($value, Languages::class)); |
113
|
|
|
|
114
|
3 |
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
3 |
|
public function addLanguage(string $lang, string $url): self |
118
|
|
|
{ |
119
|
3 |
|
$this->metaService->addAlternateLanguage(...array_values( |
|
|
|
|
120
|
3 |
|
$this->parseValue( |
121
|
3 |
|
[compact('lang', 'url')], |
122
|
3 |
|
Languages::class |
123
|
3 |
|
)[0] |
124
|
|
|
)); |
125
|
|
|
|
126
|
3 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
9 |
|
protected function getRawFields(): array |
130
|
|
|
{ |
131
|
9 |
|
return $this->modelSeoData; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check looks for function calls that miss required arguments.