1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\Seoable\Protocols; |
4
|
|
|
|
5
|
|
|
use MadWeb\Seoable\Fields\TwitterCard\Description; |
6
|
|
|
use MadWeb\Seoable\Fields\TwitterCard\Images; |
7
|
|
|
use MadWeb\Seoable\Fields\TwitterCard\Site; |
8
|
|
|
use MadWeb\Seoable\Fields\TwitterCard\Title; |
9
|
|
|
use MadWeb\Seoable\Fields\TwitterCard\Type; |
10
|
|
|
use MadWeb\Seoable\Fields\TwitterCard\Url; |
11
|
|
|
use MadWeb\Seoable\Fields\TwitterCard\Values; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @method TwitterCard setTitleRaw(string $value) |
15
|
|
|
* @method TwitterCard setDescriptionRaw(string $value) |
16
|
|
|
* @method TwitterCard setUrlRaw(string $value) |
17
|
|
|
* @method TwitterCard setSiteRaw(string $value) |
18
|
|
|
* @method TwitterCard setTypeRaw(string $value) |
19
|
|
|
* @method TwitterCard setImagesRaw(array|string $value) |
20
|
|
|
* @method TwitterCard setValuesRaw(array $value) |
21
|
|
|
* @method TwitterCard addValueRaw(string $key, mixed $value) |
22
|
|
|
*/ |
23
|
|
|
class TwitterCard extends Protocol |
24
|
|
|
{ |
25
|
|
|
/** @param array|string $value */ |
26
|
3 |
|
public function setTitle($value, string $templateKey = ''): self |
27
|
|
|
{ |
28
|
3 |
|
$this->twitterCardService->setTitle($this->parseValue( |
29
|
3 |
|
$value, |
30
|
3 |
|
$templateKey ? new Title($value, $this->model, $templateKey) : Title::class |
31
|
|
|
)); |
32
|
|
|
|
33
|
3 |
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** @param array|string $value */ |
37
|
3 |
|
public function setDescription($value, string $templateKey = ''): self |
38
|
|
|
{ |
39
|
3 |
|
$this->twitterCardService->setDescription($this->parseValue( |
40
|
3 |
|
$value, |
41
|
3 |
|
$templateKey ? new Description($value, $this->model, $templateKey) : Description::class |
42
|
|
|
)); |
43
|
|
|
|
44
|
3 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
3 |
|
public function setUrl(string $value): self |
48
|
|
|
{ |
49
|
3 |
|
$this->twitterCardService->setUrl($this->parseValue($value, Url::class)); |
50
|
|
|
|
51
|
3 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
3 |
|
public function setSite(string $value): self |
55
|
|
|
{ |
56
|
3 |
|
$this->twitterCardService->setSite($this->parseValue($value, Site::class)); |
57
|
|
|
|
58
|
3 |
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
3 |
|
public function setType(string $value): self |
62
|
|
|
{ |
63
|
3 |
|
$this->twitterCardService->setType($this->parseValue($value, Type::class)); |
64
|
|
|
|
65
|
3 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** @param array|string $value */ |
69
|
3 |
|
public function setImages($value): self |
70
|
|
|
{ |
71
|
3 |
|
$this->twitterCardService->setImage($this->parseValue($value, Images::class)); |
72
|
|
|
|
73
|
3 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
3 |
|
public function setValues(array $value): self |
77
|
|
|
{ |
78
|
3 |
|
foreach ($this->parseValue($value, Values::class) as $item) { |
79
|
3 |
|
$this->twitterCardService->addValue(...array_values($item)); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
3 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** @param array|string $value */ |
86
|
3 |
|
public function addValue(string $key, $value): self |
87
|
|
|
{ |
88
|
3 |
|
$this->twitterCardService->addValue( |
|
|
|
|
89
|
3 |
|
...array_values( |
|
|
|
|
90
|
3 |
|
$this->parseValue([compact('key', 'value')], Values::class)[0] |
91
|
|
|
) |
92
|
|
|
); |
93
|
|
|
|
94
|
3 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
3 |
|
protected function getRawFields(): array |
98
|
|
|
{ |
99
|
3 |
|
return $this->modelSeoData['twitter_card'] ?? []; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check looks for function calls that miss required arguments.