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