1 | <?php |
||
18 | class SafeValidator extends ConstraintValidator |
||
19 | { |
||
20 | /** |
||
21 | * Google safe browsing endpoint. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | const ENDPOINT = 'https://sb-ssl.google.com/safebrowsing/api/lookup'; |
||
26 | |||
27 | /** |
||
28 | * HTTP client. |
||
29 | * |
||
30 | * @var ClientInterface |
||
31 | */ |
||
32 | private $httpClient; |
||
33 | |||
34 | /** |
||
35 | * Validator cache. |
||
36 | * |
||
37 | * @var Cache |
||
38 | */ |
||
39 | private $cache; |
||
40 | |||
41 | /** |
||
42 | * Request configurations. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | private $configs = []; |
||
47 | |||
48 | /** |
||
49 | * Constructor with attributes initialization. |
||
50 | */ |
||
51 | 24 | public function __construct(array $configs = []) |
|
57 | |||
58 | /** |
||
59 | * Sets the HTTP client. |
||
60 | * |
||
61 | * @param ClientInterface $httpClient The HTTP client. |
||
62 | */ |
||
63 | 24 | public function setHttpClient(ClientInterface $httpClient) |
|
67 | |||
68 | /** |
||
69 | * Sets the Validator cache. |
||
70 | * |
||
71 | * @param Cache $cache The caching implementation. |
||
72 | */ |
||
73 | 3 | public function setCache(Cache $cache) |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 24 | public function validate($value, Constraint $constraint) |
|
96 | |||
97 | /** |
||
98 | * Gets service output and cache it. |
||
99 | * |
||
100 | * @param string $url URL or domain. |
||
101 | * |
||
102 | * @return string|false |
||
103 | */ |
||
104 | 18 | private function getResponse($url) |
|
115 | |||
116 | /** |
||
117 | * Gets service output. |
||
118 | * |
||
119 | * @param string $url URL or domain. |
||
120 | * |
||
121 | * @return string|false |
||
122 | */ |
||
123 | 18 | private function getHttpClientOutput($url) |
|
135 | } |
||
136 |