|
1
|
|
|
<?php namespace Arcanedev\SeoHelper\Entities; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\SeoHelper\Contracts\Entities\Webmasters as WebmastersContract; |
|
4
|
|
|
use Arcanedev\Support\Traits\Configurable; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class Webmasters |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\SeoHelper\Entities |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class Webmasters implements WebmastersContract |
|
13
|
|
|
{ |
|
14
|
|
|
/* ----------------------------------------------------------------- |
|
15
|
|
|
| Traits |
|
16
|
|
|
| ----------------------------------------------------------------- |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use Configurable; |
|
20
|
|
|
|
|
21
|
|
|
/* ----------------------------------------------------------------- |
|
22
|
|
|
| Properties |
|
23
|
|
|
| ----------------------------------------------------------------- |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The supported webmasters. |
|
28
|
|
|
* |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $supported = [ |
|
32
|
|
|
'google' => 'google-site-verification', |
|
33
|
|
|
'bing' => 'msvalidate.01', |
|
34
|
|
|
'alexa' => 'alexaVerifyID', |
|
35
|
|
|
'pinterest' => 'p:domain_verify', |
|
36
|
|
|
'yandex' => 'yandex-verification' |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The meta collection. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \Arcanedev\SeoHelper\Contracts\Entities\MetaCollection |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $metas; |
|
45
|
|
|
|
|
46
|
|
|
/* ----------------------------------------------------------------- |
|
47
|
|
|
| Constructor |
|
48
|
|
|
| ----------------------------------------------------------------- |
|
49
|
|
|
*/ |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Create Webmasters instance. |
|
53
|
|
|
* |
|
54
|
|
|
* @param array $configs |
|
55
|
|
|
*/ |
|
56
|
108 |
|
public function __construct(array $configs = []) |
|
57
|
|
|
{ |
|
58
|
108 |
|
$this->setConfigs($configs); |
|
59
|
|
|
|
|
60
|
108 |
|
$this->reset(); |
|
61
|
108 |
|
$this->init(); |
|
62
|
108 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Start the engine. |
|
66
|
|
|
*/ |
|
67
|
108 |
|
private function init() |
|
68
|
|
|
{ |
|
69
|
108 |
|
foreach ($this->configs as $webmaster => $content) { |
|
70
|
108 |
|
$this->add($webmaster, $content); |
|
71
|
|
|
} |
|
72
|
108 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/* ----------------------------------------------------------------- |
|
75
|
|
|
| Getters & Setters |
|
76
|
|
|
| ----------------------------------------------------------------- |
|
77
|
|
|
*/ |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get the webmaster meta name. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $webmaster |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
108 |
|
private function getWebmasterName($webmaster) |
|
87
|
|
|
{ |
|
88
|
108 |
|
return $this->isSupported($webmaster) |
|
89
|
108 |
|
? $this->supported[$webmaster] |
|
90
|
108 |
|
: null; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get all the metas collection. |
|
95
|
|
|
* |
|
96
|
|
|
* @return \Arcanedev\SeoHelper\Contracts\Entities\MetaCollection |
|
97
|
|
|
*/ |
|
98
|
3 |
|
public function all() |
|
99
|
|
|
{ |
|
100
|
3 |
|
return $this->metas; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/* ----------------------------------------------------------------- |
|
104
|
|
|
| Main Methods |
|
105
|
|
|
| ----------------------------------------------------------------- |
|
106
|
|
|
*/ |
|
107
|
|
|
/** |
|
108
|
|
|
* Make Webmaster instance. |
|
109
|
|
|
* |
|
110
|
|
|
* @param array $webmasters |
|
111
|
|
|
* |
|
112
|
|
|
* @return \Arcanedev\SeoHelper\Entities\Webmasters |
|
113
|
|
|
*/ |
|
114
|
6 |
|
public static function make(array $webmasters = []) |
|
115
|
|
|
{ |
|
116
|
6 |
|
return new self($webmasters); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Add a webmaster to collection. |
|
121
|
|
|
* |
|
122
|
|
|
* @param string $webmaster |
|
123
|
|
|
* @param string $content |
|
124
|
|
|
* |
|
125
|
|
|
* @return \Arcanedev\SeoHelper\Entities\Webmasters |
|
126
|
|
|
*/ |
|
127
|
108 |
|
public function add($webmaster, $content) |
|
128
|
|
|
{ |
|
129
|
108 |
|
if ( ! is_null($name = $this->getWebmasterName($webmaster))) { |
|
130
|
108 |
|
$this->metas->add($name, $content); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
108 |
|
return $this; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Reset the webmaster collection. |
|
138
|
|
|
* |
|
139
|
|
|
* @return \Arcanedev\SeoHelper\Entities\Webmasters |
|
140
|
|
|
*/ |
|
141
|
108 |
|
public function reset() |
|
142
|
|
|
{ |
|
143
|
108 |
|
$this->metas = new MetaCollection; |
|
144
|
|
|
|
|
145
|
108 |
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Render the tag. |
|
150
|
|
|
* |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
81 |
|
public function render() |
|
154
|
|
|
{ |
|
155
|
81 |
|
return $this->metas->render(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Render the tag. |
|
160
|
|
|
* |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
12 |
|
public function __toString() |
|
164
|
|
|
{ |
|
165
|
12 |
|
return $this->render(); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/* ----------------------------------------------------------------- |
|
169
|
|
|
| Check Methods |
|
170
|
|
|
| ----------------------------------------------------------------- |
|
171
|
|
|
*/ |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Check if the webmaster is supported. |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $webmaster |
|
177
|
|
|
* |
|
178
|
|
|
* @return bool |
|
179
|
|
|
*/ |
|
180
|
108 |
|
private function isSupported($webmaster) |
|
181
|
|
|
{ |
|
182
|
108 |
|
return array_key_exists($webmaster, $this->supported); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|