1 | <?php |
||
12 | final class Gravatar |
||
13 | { |
||
14 | /** |
||
15 | * Gravatar endpoints. |
||
16 | */ |
||
17 | private const HTTP_ENDPOINT = 'http://www.gravatar.com'; |
||
18 | private const HTTPS_ENDPOINT = 'https://secure.gravatar.com'; |
||
19 | |||
20 | /** |
||
21 | * Minimum image size |
||
22 | * |
||
23 | * @var int |
||
24 | */ |
||
25 | private const MINIMUM_IMAGE_SIZE = 1; |
||
26 | |||
27 | /** |
||
28 | * Maximum image size |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | private const MAXIMUM_IMAGE_SIZE = 2048; |
||
33 | |||
34 | 16 | /** |
|
35 | * Default Image Keywords |
||
36 | 16 | * |
|
37 | 16 | * @var array |
|
38 | 16 | */ |
|
39 | private const DEFAULT_IMAGE_KEYWORDS = [ |
||
40 | '404', |
||
41 | 'mp', |
||
42 | 'identicon', |
||
43 | 'monsterid', |
||
44 | 'wavatar', |
||
45 | 'retro', |
||
46 | 'robohash', |
||
47 | 'blank' |
||
48 | ]; |
||
49 | 5 | ||
50 | /** |
||
51 | 5 | * Image ratings |
|
52 | 4 | * |
|
53 | * @var array |
||
54 | 4 | */ |
|
55 | 2 | private const IMAGE_RATINGS = [ |
|
56 | 2 | 'g', |
|
57 | 'pg', |
||
58 | 4 | 'r', |
|
59 | 'x' |
||
60 | ]; |
||
61 | |||
62 | /** |
||
63 | * @var array |
||
64 | */ |
||
65 | private $defaults = []; |
||
66 | |||
67 | /** |
||
68 | * Whether to use HTTPS endpoint. |
||
69 | 10 | * |
|
70 | * @var bool |
||
71 | 10 | */ |
|
72 | private $secure; |
||
73 | |||
74 | public function __construct(array $defaults = [], bool $secure = true) |
||
79 | |||
80 | /** |
||
81 | * Returns an Avatar URL. |
||
82 | 3 | */ |
|
83 | public function avatar(string $email, array $options = [], ?bool $secure = null, bool $validateOptions = false): string |
||
99 | |||
100 | /** |
||
101 | * Returns a profile URL. |
||
102 | */ |
||
103 | public function profile(string $email, ?bool $secure = null): string |
||
107 | 15 | ||
108 | /** |
||
109 | 15 | * Returns a vCard URL. |
|
110 | 4 | */ |
|
111 | public function vcard(string $email, ?bool $secure = null): string |
||
115 | |||
116 | /** |
||
117 | * Returns a QR Code URL. |
||
118 | */ |
||
119 | public function qrCode(string $email, ?bool $secure = null): string |
||
123 | |||
124 | 11 | /** |
|
125 | * Creates a hash from an email address. |
||
126 | 11 | */ |
|
127 | private function createEmailHash(string $email): string |
||
135 | |||
136 | private function validateOptions(array $options): array |
||
216 | |||
217 | /** |
||
218 | * Builds the URL based on the given parameters. |
||
219 | */ |
||
220 | private function buildUrl(string $resource, ?bool $secure): string |
||
228 | } |
||
229 |