1 | <?php namespace Arcanedev\NoCaptcha\Utilities; |
||
11 | class Attributes implements AttributesInterface |
||
12 | { |
||
13 | /* ------------------------------------------------------------------------------------------------ |
||
14 | | Properties |
||
15 | | ------------------------------------------------------------------------------------------------ |
||
16 | */ |
||
17 | /** |
||
18 | * Attribute collection. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $items = []; |
||
23 | |||
24 | /* ------------------------------------------------------------------------------------------------ |
||
25 | | Getters & Setters |
||
26 | | ------------------------------------------------------------------------------------------------ |
||
27 | */ |
||
28 | /** |
||
29 | * Get all items. |
||
30 | * |
||
31 | * @param string $siteKey |
||
32 | * |
||
33 | * @return array |
||
34 | */ |
||
35 | 132 | protected function getItems($siteKey) |
|
36 | { |
||
37 | 132 | return array_merge( |
|
38 | 132 | $this->getDefaultAttributes($siteKey), |
|
39 | 132 | $this->items |
|
40 | 99 | ); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get Default attributes. |
||
45 | * |
||
46 | * @param string $siteKey |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | 132 | private function getDefaultAttributes($siteKey) |
|
51 | { |
||
52 | return [ |
||
53 | 132 | 'class' => 'g-recaptcha', |
|
54 | 132 | 'data-sitekey' => $siteKey, |
|
55 | 99 | ]; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Set items. |
||
60 | * |
||
61 | * @param array $items |
||
62 | * |
||
63 | * @return self |
||
64 | */ |
||
65 | 132 | private function setItems(array $items) |
|
66 | { |
||
67 | 132 | $this->items = $items; |
|
68 | |||
69 | 132 | $this->checkAttributes(); |
|
70 | |||
71 | 132 | return $this; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Get an item value by name. |
||
76 | * |
||
77 | * @param string $name |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | 132 | private function getItem($name) |
|
82 | { |
||
83 | 132 | if ( ! $this->hasItem($name)) { |
|
84 | 132 | return null; |
|
85 | } |
||
86 | |||
87 | 84 | return $this->items[$name]; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * Set an item. |
||
92 | * |
||
93 | * @param string $name |
||
94 | * @param string $value |
||
95 | * |
||
96 | * @return self |
||
97 | */ |
||
98 | 84 | private function setItem($name, $value) |
|
99 | { |
||
100 | 84 | $this->items[$name] = $value; |
|
101 | |||
102 | 84 | return $this; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Get image type attribute. |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | 12 | public function getImageAttribute() |
|
114 | |||
115 | /** |
||
116 | * Get audio type attribute. |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | 12 | public function getAudioAttribute() |
|
124 | |||
125 | /* ------------------------------------------------------------------------------------------------ |
||
126 | | Main functions |
||
127 | | ------------------------------------------------------------------------------------------------ |
||
128 | */ |
||
129 | /** |
||
130 | * Build attributes. |
||
131 | * |
||
132 | * @param string $siteKey |
||
133 | * @param array $items |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 132 | public function build($siteKey, array $items = []) |
|
149 | |||
150 | /* ------------------------------------------------------------------------------------------------ |
||
151 | | Check functions |
||
152 | | ------------------------------------------------------------------------------------------------ |
||
153 | */ |
||
154 | /** |
||
155 | * Check attributes. |
||
156 | */ |
||
157 | 132 | private function checkAttributes() |
|
163 | |||
164 | /** |
||
165 | * Check type attribute. |
||
166 | */ |
||
167 | 132 | private function checkTypeAttribute() |
|
171 | |||
172 | /** |
||
173 | * Check theme attribute. |
||
174 | */ |
||
175 | 132 | private function checkThemeAttribute() |
|
179 | |||
180 | /** |
||
181 | * Check size attribute. |
||
182 | */ |
||
183 | 132 | private function checkSizeAttribute() |
|
187 | |||
188 | /** |
||
189 | * Check data Attribute. |
||
190 | * |
||
191 | * @param string $name |
||
192 | * @param string $default |
||
193 | * @param array $available |
||
194 | */ |
||
195 | 132 | private function checkDataAttribute($name, $default, array $available) |
|
207 | |||
208 | /** |
||
209 | * Check if has an item. |
||
210 | * |
||
211 | * @param string $name |
||
212 | * |
||
213 | * @return bool |
||
214 | */ |
||
215 | 132 | private function hasItem($name) |
|
219 | } |
||
220 |