Commit | Line | Data |
---|---|---|
3a0d0bbd CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
3a0d0bbd | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
3a0d0bbd CW |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
4094935a AP |
28 | use GuzzleHttp\Client; |
29 | ||
3a0d0bbd CW |
30 | /** |
31 | * | |
32 | * @package CRM | |
6b83d5bd | 33 | * @copyright CiviCRM LLC (c) 2004-2019 |
3a0d0bbd CW |
34 | */ |
35 | abstract class CRM_Utils_Check_Component { | |
36 | ||
37 | /** | |
38 | * Should these checks be run? | |
39 | * | |
40 | * @return bool | |
41 | */ | |
42 | public function isEnabled() { | |
43 | return TRUE; | |
44 | } | |
45 | ||
46 | /** | |
47 | * Run all checks in this class. | |
48 | * | |
49 | * @return array | |
50 | * [CRM_Utils_Check_Message] | |
51 | */ | |
52 | public function checkAll() { | |
53 | $messages = array(); | |
54 | foreach (get_class_methods($this) as $method) { | |
55 | if ($method !== 'checkAll' && strpos($method, 'check') === 0) { | |
56 | $messages = array_merge($messages, $this->$method()); | |
57 | } | |
58 | } | |
59 | return $messages; | |
60 | } | |
d631cdc8 | 61 | |
4094935a AP |
62 | /** |
63 | * Check if file exists on given URL. | |
64 | * | |
65 | * @param $url | |
66 | * @return bool | |
67 | * @throws \GuzzleHttp\Exception\GuzzleException | |
68 | */ | |
5b987d84 | 69 | public function fileExists($url, $timeout = 0.50) { |
4094935a AP |
70 | $fileExists = FALSE; |
71 | try { | |
72 | $guzzleClient = new GuzzleHttp\Client(); | |
73 | $guzzleResponse = $guzzleClient->request('GET', $url, array( | |
74 | 'timeout' => $timeout, | |
75 | )); | |
76 | $fileExists = ($guzzleResponse->getStatusCode() == 200); | |
77 | } | |
78 | catch (Exception $e) { | |
79 | echo $e->getMessage(); | |
80 | } | |
81 | return $fileExists; | |
82 | } | |
83 | ||
137d9cf0 | 84 | } |