1 | <?php |
||
15 | class Insight extends AbstractHtmlElement |
||
16 | { |
||
17 | /** |
||
18 | * URL to Insight service |
||
19 | */ |
||
20 | const INSIGHT_URL = 'http://insight.sensiolabs.com/projects'; |
||
21 | |||
22 | /** |
||
23 | * Secure URL to Insight service |
||
24 | */ |
||
25 | const INSIGHT_URL_SECURE = 'https://insight.sensiolabs.com/projects'; |
||
26 | |||
27 | /** |
||
28 | * Default value whether img should be wrapped into html <a> tag |
||
29 | */ |
||
30 | const LINKED = true; |
||
31 | |||
32 | /** |
||
33 | * Insight size |
||
34 | */ |
||
35 | const SIZE_BIG = 'big'; |
||
36 | const SIZE_SMALL = 'small'; |
||
37 | const SIZE_MINI = 'mini'; |
||
38 | |||
39 | /** |
||
40 | * Default options |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | const OPTIONS = [ |
||
45 | 'badge_size' => self::SIZE_BIG, |
||
46 | 'secure' => self::INSIGHT_URL_SECURE, |
||
47 | 'linked' => self::LINKED, |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * Insight project key |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $projectKey; |
||
56 | |||
57 | /** |
||
58 | * Options |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $options = self::OPTIONS; |
||
63 | |||
64 | /** |
||
65 | * Attributes for HTML image tag |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $attribs = []; |
||
70 | |||
71 | /** |
||
72 | * Returns an image from Insight's service. |
||
73 | * $options may include the following: |
||
74 | * - 'size' size of img to return |
||
75 | * - 'secure' bool load from the SSL or Non-SSL location |
||
76 | * - 'linked' bool whether img should be wrapped into html a tag |
||
77 | * |
||
78 | * @param string|null $projectKey Project key.. |
||
79 | * @param null|array $options Options |
||
80 | * @param null|array $attribs |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function __invoke($projectKey = '', $options = [], $attribs = []) |
||
99 | |||
100 | /** |
||
101 | * Return badge html |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function __toString() |
||
109 | |||
110 | /** |
||
111 | * Configure state |
||
112 | * |
||
113 | * @param array $options |
||
114 | * @return $this |
||
115 | */ |
||
116 | public function setOptions(array $options) |
||
127 | |||
128 | /** |
||
129 | * Get project url |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | protected function getProjectUrl() |
||
139 | |||
140 | /** |
||
141 | * Get img url |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | protected function getImgUrl() |
||
151 | |||
152 | /** |
||
153 | * Get URL to Insight's service |
||
154 | * |
||
155 | * @return string URL |
||
156 | */ |
||
157 | protected function getInsightUrl() |
||
161 | |||
162 | /** |
||
163 | * Return valid image tag |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | public function getImgTag() |
||
176 | |||
177 | /** |
||
178 | * Return valid a tag |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getATag() |
||
193 | |||
194 | /** |
||
195 | * Set attribs for image tag |
||
196 | * |
||
197 | * Warning! You shouldn't set src attrib for image tag. |
||
198 | * This attrib is overwritten in protected method setSrcAttribForImg(). |
||
199 | * This method(_setSrcAttribForImg) is called in public method getImgTag(). |
||
200 | * |
||
201 | * @param array $attribs |
||
202 | * @return $this |
||
203 | */ |
||
204 | public function setAttribs(array $attribs) |
||
210 | |||
211 | /** |
||
212 | * Get attribs of image |
||
213 | * |
||
214 | * Warning! |
||
215 | * If you set src attrib, you get it, but this value will be overwritten in |
||
216 | * protected method setSrcAttribForImg(). And finally your get other src |
||
217 | * value! |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | public function getAttribs() |
||
225 | |||
226 | /** |
||
227 | * Set project key |
||
228 | * |
||
229 | * @param string $projectKey |
||
230 | * @return $this |
||
231 | */ |
||
232 | public function setProjectKey($projectKey) |
||
238 | |||
239 | /** |
||
240 | * Get project key |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | public function getProjectKey() |
||
248 | |||
249 | /** |
||
250 | * Set linked |
||
251 | * |
||
252 | * @param string $linked Define whether img should be wrapped into html a tag |
||
253 | * @return $this |
||
254 | */ |
||
255 | public function setLinked($linked) |
||
261 | |||
262 | /** |
||
263 | * Set badge size |
||
264 | * |
||
265 | * @param string $size Size of img must be one of the: big, small, mini |
||
266 | * @return $this |
||
267 | */ |
||
268 | public function setBadgeSize($size) |
||
274 | |||
275 | /** |
||
276 | * Get badge size |
||
277 | * |
||
278 | * @return string The badge size |
||
279 | */ |
||
280 | public function getBadgeSize() |
||
284 | |||
285 | /** |
||
286 | * Load from an SSL or No-SSL location? |
||
287 | * |
||
288 | * @param bool $flag |
||
289 | * @return $this |
||
290 | */ |
||
291 | public function setSecure($flag) |
||
297 | |||
298 | /** |
||
299 | * Get an SSL or a No-SSL location |
||
300 | * |
||
301 | * @return bool |
||
302 | */ |
||
303 | public function getSecure() |
||
311 | |||
312 | /** |
||
313 | * Set src attrib for image |
||
314 | * |
||
315 | * You shouldn't set an own url value! |
||
316 | * It sets value, uses protected method getImgUrl. |
||
317 | * |
||
318 | * If already exists, it will be overwritten. |
||
319 | * |
||
320 | * @return void |
||
321 | */ |
||
322 | protected function setSrcAttribForImg() |
||
328 | } |
||
329 |