@@ -9,73 +9,73 @@ |
||
9 | 9 | */ |
10 | 10 | class VehicleReduced extends \Route4Me\Common |
11 | 11 | { |
12 | - /** The vehicle ID |
|
13 | - * @var string $vehicle_id |
|
14 | - */ |
|
15 | - public $vehicle_id; |
|
12 | + /** The vehicle ID |
|
13 | + * @var string $vehicle_id |
|
14 | + */ |
|
15 | + public $vehicle_id; |
|
16 | 16 | |
17 | - /** Vehicle alias |
|
18 | - * @var string $vehicle_alias |
|
19 | - */ |
|
20 | - public $vehicle_alias; |
|
17 | + /** Vehicle alias |
|
18 | + * @var string $vehicle_alias |
|
19 | + */ |
|
20 | + public $vehicle_alias; |
|
21 | 21 | |
22 | - /** Vehicle VIN |
|
23 | - * @var string $vehicle_vin |
|
24 | - */ |
|
25 | - public $vehicle_vin; |
|
22 | + /** Vehicle VIN |
|
23 | + * @var string $vehicle_vin |
|
24 | + */ |
|
25 | + public $vehicle_vin; |
|
26 | 26 | |
27 | - /** A license plate of the vehicle. |
|
28 | - * @var string $vehicle_license_plate |
|
29 | - */ |
|
30 | - public $vehicle_license_plate; |
|
27 | + /** A license plate of the vehicle. |
|
28 | + * @var string $vehicle_license_plate |
|
29 | + */ |
|
30 | + public $vehicle_license_plate; |
|
31 | 31 | |
32 | - /** Vehicle maker brend. |
|
33 | - * <para>Available values:</para> |
|
34 | - * "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc", |
|
35 | - * <para>"hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi", </para> |
|
36 | - * "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota", |
|
37 | - * <para>"volvo", "western star" </para> |
|
38 | - * @var string $vehicle_make |
|
39 | - */ |
|
40 | - public $vehicle_make; |
|
32 | + /** Vehicle maker brend. |
|
33 | + * <para>Available values:</para> |
|
34 | + * "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc", |
|
35 | + * <para>"hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi", </para> |
|
36 | + * "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota", |
|
37 | + * <para>"volvo", "western star" </para> |
|
38 | + * @var string $vehicle_make |
|
39 | + */ |
|
40 | + public $vehicle_make; |
|
41 | 41 | |
42 | - /** Vehicle model year |
|
43 | - * @var integer $vehicle_model_year |
|
44 | - */ |
|
45 | - public $vehicle_model_year; |
|
42 | + /** Vehicle model year |
|
43 | + * @var integer $vehicle_model_year |
|
44 | + */ |
|
45 | + public $vehicle_model_year; |
|
46 | 46 | |
47 | - /** Vehicle model |
|
48 | - * @var string $vehicle_model |
|
49 | - */ |
|
50 | - public $vehicle_model; |
|
47 | + /** Vehicle model |
|
48 | + * @var string $vehicle_model |
|
49 | + */ |
|
50 | + public $vehicle_model; |
|
51 | 51 | |
52 | - /** The year, vehicle was acquired |
|
53 | - * @var integer $vehicle_year_acquired |
|
54 | - */ |
|
55 | - public $vehicle_year_acquired; |
|
52 | + /** The year, vehicle was acquired |
|
53 | + * @var integer $vehicle_year_acquired |
|
54 | + */ |
|
55 | + public $vehicle_year_acquired; |
|
56 | 56 | |
57 | - /** A cost of the new vehicle |
|
58 | - * @var float $vehicle_cost_new |
|
59 | - */ |
|
60 | - public $vehicle_cost_new; |
|
57 | + /** A cost of the new vehicle |
|
58 | + * @var float $vehicle_cost_new |
|
59 | + */ |
|
60 | + public $vehicle_cost_new; |
|
61 | 61 | |
62 | - /** If true, the vehicle was purchased new. |
|
63 | - * @var boolean $purchased_new |
|
64 | - */ |
|
65 | - public $purchased_new; |
|
62 | + /** If true, the vehicle was purchased new. |
|
63 | + * @var boolean $purchased_new |
|
64 | + */ |
|
65 | + public $purchased_new; |
|
66 | 66 | |
67 | - /** Start date of the license |
|
68 | - * @var string $license_start_date |
|
69 | - */ |
|
70 | - public $license_start_date; |
|
67 | + /** Start date of the license |
|
68 | + * @var string $license_start_date |
|
69 | + */ |
|
70 | + public $license_start_date; |
|
71 | 71 | |
72 | - /** End date of the license |
|
73 | - * @var string $license_end_date |
|
74 | - */ |
|
75 | - public $license_end_date; |
|
72 | + /** End date of the license |
|
73 | + * @var string $license_end_date |
|
74 | + */ |
|
75 | + public $license_end_date; |
|
76 | 76 | |
77 | - /** If equal to '1', the vehicle is operational. |
|
78 | - * @var boolean $is_operational |
|
79 | - */ |
|
80 | - public $is_operational; |
|
77 | + /** If equal to '1', the vehicle is operational. |
|
78 | + * @var boolean $is_operational |
|
79 | + */ |
|
80 | + public $is_operational; |
|
81 | 81 | } |
@@ -9,23 +9,23 @@ |
||
9 | 9 | */ |
10 | 10 | class VehicleLocationItem extends \Route4Me\Common |
11 | 11 | { |
12 | - /** The vehicle ID |
|
13 | - * @var string $vehicle_id |
|
14 | - */ |
|
15 | - public $vehicle_id; |
|
12 | + /** The vehicle ID |
|
13 | + * @var string $vehicle_id |
|
14 | + */ |
|
15 | + public $vehicle_id; |
|
16 | 16 | |
17 | - /** When a vehicle activity was detected. |
|
18 | - * @var integer $activity_timestamp |
|
19 | - */ |
|
20 | - public $activity_timestamp; |
|
17 | + /** When a vehicle activity was detected. |
|
18 | + * @var integer $activity_timestamp |
|
19 | + */ |
|
20 | + public $activity_timestamp; |
|
21 | 21 | |
22 | - /** Latitude of a vehicle position. |
|
23 | - * @var float $lat |
|
24 | - */ |
|
25 | - public $lat; |
|
22 | + /** Latitude of a vehicle position. |
|
23 | + * @var float $lat |
|
24 | + */ |
|
25 | + public $lat; |
|
26 | 26 | |
27 | - /** Longitude of a vehicle position |
|
28 | - * @var float $lng |
|
29 | - */ |
|
30 | - public $lng; |
|
27 | + /** Longitude of a vehicle position |
|
28 | + * @var float $lng |
|
29 | + */ |
|
30 | + public $lng; |
|
31 | 31 | } |
@@ -11,23 +11,23 @@ |
||
11 | 11 | */ |
12 | 12 | class VehicleResponse extends Common |
13 | 13 | { |
14 | - /** Vehicle data |
|
15 | - * @var DataVehicle $data |
|
16 | - */ |
|
17 | - public $data = []; |
|
14 | + /** Vehicle data |
|
15 | + * @var DataVehicle $data |
|
16 | + */ |
|
17 | + public $data = []; |
|
18 | 18 | |
19 | - public static function fromArray(array $params) |
|
20 | - { |
|
21 | - $vehResp = new self(); |
|
19 | + public static function fromArray(array $params) |
|
20 | + { |
|
21 | + $vehResp = new self(); |
|
22 | 22 | |
23 | - foreach ($params as $key => $value) { |
|
24 | - if (is_null(Common::getValue($params, $key))) { |
|
25 | - continue; |
|
26 | - } |
|
27 | - if (property_exists($vehResp, $key)) { |
|
28 | - $vehResp->$key = $value; |
|
29 | - } |
|
30 | - } |
|
31 | - return $vehResp; |
|
32 | - } |
|
23 | + foreach ($params as $key => $value) { |
|
24 | + if (is_null(Common::getValue($params, $key))) { |
|
25 | + continue; |
|
26 | + } |
|
27 | + if (property_exists($vehResp, $key)) { |
|
28 | + $vehResp->$key = $value; |
|
29 | + } |
|
30 | + } |
|
31 | + return $vehResp; |
|
32 | + } |
|
33 | 33 | } |
@@ -11,78 +11,78 @@ |
||
11 | 11 | */ |
12 | 12 | class VehicleProfilesResponse extends Common |
13 | 13 | { |
14 | - /** Current page of the paginated vehicle profiles list. |
|
15 | - * @var integer $current_page |
|
16 | - */ |
|
17 | - public $current_page; |
|
18 | - |
|
19 | - /** An array of the vehicle profiles |
|
20 | - * @var VehileProfile[] $data |
|
21 | - */ |
|
22 | - public $data = []; |
|
23 | - |
|
24 | - /** URL to the first page of the paginated vehicle profiles list. |
|
25 | - * @var string $first_page_url |
|
26 | - */ |
|
27 | - public $first_page_url; |
|
28 | - |
|
29 | - /** From which vehicle profile is starting the page |
|
30 | - * @var integer $from |
|
31 | - */ |
|
32 | - public $from; |
|
33 | - |
|
34 | - /** Last page |
|
35 | - * @var integer $last_page |
|
36 | - */ |
|
37 | - public $last_page; |
|
38 | - |
|
39 | - /** URL to the last page of the paginated vehicle profiles list. |
|
40 | - * @var string $last_page_url |
|
41 | - */ |
|
42 | - public $last_page_url; |
|
43 | - |
|
44 | - /** URL to the next page of the paginated vehicle profiles list. |
|
45 | - * @var string $next_page_url |
|
46 | - */ |
|
47 | - public $next_page_url; |
|
48 | - |
|
49 | - /** Path to the API endpoint |
|
50 | - * @var string $path |
|
51 | - */ |
|
52 | - public $path; |
|
53 | - |
|
54 | - /** Vehicles number per page |
|
55 | - * @var integer $per_page |
|
56 | - */ |
|
57 | - public $per_page; |
|
58 | - |
|
59 | - /** URL to the previous page |
|
60 | - * @var string $prev_page_url |
|
61 | - */ |
|
62 | - public $prev_page_url; |
|
63 | - |
|
64 | - /** To which vehicle profile is ending the page |
|
65 | - * @var integer $to |
|
66 | - */ |
|
67 | - public $to; |
|
68 | - |
|
69 | - /** Total number of the vehicles. |
|
70 | - * @var integer $total |
|
71 | - */ |
|
72 | - public $total; |
|
73 | - |
|
74 | - public static function fromArray(array $params) |
|
75 | - { |
|
76 | - $profResp = new self(); |
|
77 | - |
|
78 | - foreach ($params as $key => $value) { |
|
79 | - if (is_null(Common::getValue($params, $key))) { |
|
80 | - continue; |
|
81 | - } |
|
82 | - if (property_exists($profResp, $key)) { |
|
83 | - $profResp->$key = $value; |
|
84 | - } |
|
85 | - } |
|
86 | - return $profResp; |
|
87 | - } |
|
14 | + /** Current page of the paginated vehicle profiles list. |
|
15 | + * @var integer $current_page |
|
16 | + */ |
|
17 | + public $current_page; |
|
18 | + |
|
19 | + /** An array of the vehicle profiles |
|
20 | + * @var VehileProfile[] $data |
|
21 | + */ |
|
22 | + public $data = []; |
|
23 | + |
|
24 | + /** URL to the first page of the paginated vehicle profiles list. |
|
25 | + * @var string $first_page_url |
|
26 | + */ |
|
27 | + public $first_page_url; |
|
28 | + |
|
29 | + /** From which vehicle profile is starting the page |
|
30 | + * @var integer $from |
|
31 | + */ |
|
32 | + public $from; |
|
33 | + |
|
34 | + /** Last page |
|
35 | + * @var integer $last_page |
|
36 | + */ |
|
37 | + public $last_page; |
|
38 | + |
|
39 | + /** URL to the last page of the paginated vehicle profiles list. |
|
40 | + * @var string $last_page_url |
|
41 | + */ |
|
42 | + public $last_page_url; |
|
43 | + |
|
44 | + /** URL to the next page of the paginated vehicle profiles list. |
|
45 | + * @var string $next_page_url |
|
46 | + */ |
|
47 | + public $next_page_url; |
|
48 | + |
|
49 | + /** Path to the API endpoint |
|
50 | + * @var string $path |
|
51 | + */ |
|
52 | + public $path; |
|
53 | + |
|
54 | + /** Vehicles number per page |
|
55 | + * @var integer $per_page |
|
56 | + */ |
|
57 | + public $per_page; |
|
58 | + |
|
59 | + /** URL to the previous page |
|
60 | + * @var string $prev_page_url |
|
61 | + */ |
|
62 | + public $prev_page_url; |
|
63 | + |
|
64 | + /** To which vehicle profile is ending the page |
|
65 | + * @var integer $to |
|
66 | + */ |
|
67 | + public $to; |
|
68 | + |
|
69 | + /** Total number of the vehicles. |
|
70 | + * @var integer $total |
|
71 | + */ |
|
72 | + public $total; |
|
73 | + |
|
74 | + public static function fromArray(array $params) |
|
75 | + { |
|
76 | + $profResp = new self(); |
|
77 | + |
|
78 | + foreach ($params as $key => $value) { |
|
79 | + if (is_null(Common::getValue($params, $key))) { |
|
80 | + continue; |
|
81 | + } |
|
82 | + if (property_exists($profResp, $key)) { |
|
83 | + $profResp->$key = $value; |
|
84 | + } |
|
85 | + } |
|
86 | + return $profResp; |
|
87 | + } |
|
88 | 88 | } |
@@ -4,38 +4,38 @@ |
||
4 | 4 | |
5 | 5 | class VehicleTrackItem extends \Route4Me\Common |
6 | 6 | { |
7 | - /** The vehicle ID |
|
8 | - * @var string $vehicle_id |
|
9 | - */ |
|
10 | - public $vehicle_id; |
|
11 | - |
|
12 | - /** The member ID |
|
13 | - * @var integer $member_id |
|
14 | - */ |
|
15 | - public $member_id; |
|
16 | - |
|
17 | - /** Latitude of a vehicle position. |
|
18 | - * @var float $lat |
|
19 | - */ |
|
20 | - public $lat; |
|
21 | - |
|
22 | - /** Longitude of a vehicle position. |
|
23 | - * @var float $lng |
|
24 | - */ |
|
25 | - public $lng; |
|
26 | - |
|
27 | - /** The geographic altitude |
|
28 | - * @var integer $altitude |
|
29 | - */ |
|
30 | - public $altitude; |
|
31 | - |
|
32 | - /** Vehicle speed |
|
33 | - * @var integer $speed |
|
34 | - */ |
|
35 | - public $speed; |
|
36 | - |
|
37 | - /** When a vehicle activity was detected. |
|
38 | - * @var integer $timestamp |
|
39 | - */ |
|
40 | - public $timestamp; |
|
7 | + /** The vehicle ID |
|
8 | + * @var string $vehicle_id |
|
9 | + */ |
|
10 | + public $vehicle_id; |
|
11 | + |
|
12 | + /** The member ID |
|
13 | + * @var integer $member_id |
|
14 | + */ |
|
15 | + public $member_id; |
|
16 | + |
|
17 | + /** Latitude of a vehicle position. |
|
18 | + * @var float $lat |
|
19 | + */ |
|
20 | + public $lat; |
|
21 | + |
|
22 | + /** Longitude of a vehicle position. |
|
23 | + * @var float $lng |
|
24 | + */ |
|
25 | + public $lng; |
|
26 | + |
|
27 | + /** The geographic altitude |
|
28 | + * @var integer $altitude |
|
29 | + */ |
|
30 | + public $altitude; |
|
31 | + |
|
32 | + /** Vehicle speed |
|
33 | + * @var integer $speed |
|
34 | + */ |
|
35 | + public $speed; |
|
36 | + |
|
37 | + /** When a vehicle activity was detected. |
|
38 | + * @var integer $timestamp |
|
39 | + */ |
|
40 | + public $timestamp; |
|
41 | 41 | } |
@@ -6,8 +6,8 @@ |
||
6 | 6 | |
7 | 7 | class DataVehicle extends Common |
8 | 8 | { |
9 | - /** Reduced vehicle object |
|
10 | - * @var VehicleReduced $vehicle |
|
11 | - */ |
|
12 | - public $vehicle = []; |
|
9 | + /** Reduced vehicle object |
|
10 | + * @var VehicleReduced $vehicle |
|
11 | + */ |
|
12 | + public $vehicle = []; |
|
13 | 13 | } |
@@ -11,28 +11,28 @@ |
||
11 | 11 | */ |
12 | 12 | class VehicleOrderResponse extends Common |
13 | 13 | { |
14 | - /** Vehicle ID |
|
15 | - * @var string $vehicle_id |
|
16 | - */ |
|
17 | - public $vehicle_id; |
|
14 | + /** Vehicle ID |
|
15 | + * @var string $vehicle_id |
|
16 | + */ |
|
17 | + public $vehicle_id; |
|
18 | 18 | |
19 | - /** Order ID |
|
20 | - * @var integer $order_id |
|
21 | - */ |
|
22 | - public $order_id; |
|
19 | + /** Order ID |
|
20 | + * @var integer $order_id |
|
21 | + */ |
|
22 | + public $order_id; |
|
23 | 23 | |
24 | - public static function fromArray(array $params) |
|
25 | - { |
|
26 | - $ordParams = new self(); |
|
24 | + public static function fromArray(array $params) |
|
25 | + { |
|
26 | + $ordParams = new self(); |
|
27 | 27 | |
28 | - foreach ($params as $key => $value) { |
|
29 | - if (is_null(Common::getValue($params, $key))) { |
|
30 | - continue; |
|
31 | - } |
|
32 | - if (property_exists($ordParams, $key)) { |
|
33 | - $ordParams->$key = $value; |
|
34 | - } |
|
35 | - } |
|
36 | - return $ordParams; |
|
37 | - } |
|
28 | + foreach ($params as $key => $value) { |
|
29 | + if (is_null(Common::getValue($params, $key))) { |
|
30 | + continue; |
|
31 | + } |
|
32 | + if (property_exists($ordParams, $key)) { |
|
33 | + $ordParams->$key = $value; |
|
34 | + } |
|
35 | + } |
|
36 | + return $ordParams; |
|
37 | + } |
|
38 | 38 | } |
@@ -11,43 +11,43 @@ |
||
11 | 11 | */ |
12 | 12 | class VehicleTemporary extends Common |
13 | 13 | { |
14 | - /** The vehicle ID |
|
15 | - * @var integer $vehicle_id |
|
16 | - */ |
|
17 | - public $vehicle_id; |
|
18 | - |
|
19 | - /** A license plate of the vehicle. |
|
20 | - * @var string $vehicle_license_plate |
|
21 | - */ |
|
22 | - public $vehicle_license_plate; |
|
23 | - |
|
24 | - /** Member ID assigned to the temporary vehicle. |
|
25 | - * @var string $assigned_member_id |
|
26 | - */ |
|
27 | - public $assigned_member_id; |
|
28 | - |
|
29 | - /** An expiration date of the temporary vehicle. |
|
30 | - * @var string $expires_at |
|
31 | - */ |
|
32 | - public $expires_at; |
|
33 | - |
|
34 | - /** If true, an assignment forced. |
|
35 | - * @var boolean $force_assignment |
|
36 | - */ |
|
37 | - public $force_assignment; |
|
38 | - |
|
39 | - public static function fromArray(array $params) |
|
40 | - { |
|
41 | - $vehicleTemp = new self(); |
|
42 | - |
|
43 | - foreach ($params as $key => $value) { |
|
44 | - if (is_null(Common::getValue($params, $key))) { |
|
45 | - continue; |
|
46 | - } |
|
47 | - if (property_exists($vehicleTemp, $key)) { |
|
48 | - $vehicleTemp->$key = $value; |
|
49 | - } |
|
50 | - } |
|
51 | - return $vehicleTemp; |
|
52 | - } |
|
14 | + /** The vehicle ID |
|
15 | + * @var integer $vehicle_id |
|
16 | + */ |
|
17 | + public $vehicle_id; |
|
18 | + |
|
19 | + /** A license plate of the vehicle. |
|
20 | + * @var string $vehicle_license_plate |
|
21 | + */ |
|
22 | + public $vehicle_license_plate; |
|
23 | + |
|
24 | + /** Member ID assigned to the temporary vehicle. |
|
25 | + * @var string $assigned_member_id |
|
26 | + */ |
|
27 | + public $assigned_member_id; |
|
28 | + |
|
29 | + /** An expiration date of the temporary vehicle. |
|
30 | + * @var string $expires_at |
|
31 | + */ |
|
32 | + public $expires_at; |
|
33 | + |
|
34 | + /** If true, an assignment forced. |
|
35 | + * @var boolean $force_assignment |
|
36 | + */ |
|
37 | + public $force_assignment; |
|
38 | + |
|
39 | + public static function fromArray(array $params) |
|
40 | + { |
|
41 | + $vehicleTemp = new self(); |
|
42 | + |
|
43 | + foreach ($params as $key => $value) { |
|
44 | + if (is_null(Common::getValue($params, $key))) { |
|
45 | + continue; |
|
46 | + } |
|
47 | + if (property_exists($vehicleTemp, $key)) { |
|
48 | + $vehicleTemp->$key = $value; |
|
49 | + } |
|
50 | + } |
|
51 | + return $vehicleTemp; |
|
52 | + } |
|
53 | 53 | } |
@@ -119,44 +119,44 @@ |
||
119 | 119 | curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
120 | 120 | } else { |
121 | 121 | switch ($method) { |
122 | - case 'DELETE': |
|
123 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
124 | - break; |
|
125 | - case 'DELETEARRAY': |
|
126 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
127 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
128 | - break; |
|
129 | - case 'PUT': |
|
130 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
131 | - break; |
|
132 | - case 'POST': |
|
133 | - if (isset($body)) { |
|
134 | - if (isset($options['HTTPHEADER']) |
|
135 | - && strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
136 | - $bodyData = $body; |
|
137 | - } else { |
|
138 | - $bodyData = json_encode($body); |
|
139 | - } |
|
140 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
141 | - curl_setopt($ch, CURLOPT_POSTREDIR, 7); |
|
142 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
143 | - } |
|
144 | - break; |
|
145 | - case 'ADD': |
|
146 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
147 | - break; |
|
148 | - case 'PATCH': |
|
149 | - if (isset($body)) { |
|
122 | + case 'DELETE': |
|
123 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
124 | + break; |
|
125 | + case 'DELETEARRAY': |
|
126 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
127 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
128 | + break; |
|
129 | + case 'PUT': |
|
130 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
131 | + break; |
|
132 | + case 'POST': |
|
133 | + if (isset($body)) { |
|
134 | + if (isset($options['HTTPHEADER']) |
|
135 | + && strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
136 | + $bodyData = $body; |
|
137 | + } else { |
|
150 | 138 | $bodyData = json_encode($body); |
151 | - if (isset($options['HTTPHEADER'])) { |
|
152 | - if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
153 | - $bodyData = $body; |
|
154 | - } |
|
139 | + } |
|
140 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
141 | + curl_setopt($ch, CURLOPT_POSTREDIR, 7); |
|
142 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
143 | + } |
|
144 | + break; |
|
145 | + case 'ADD': |
|
146 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
147 | + break; |
|
148 | + case 'PATCH': |
|
149 | + if (isset($body)) { |
|
150 | + $bodyData = json_encode($body); |
|
151 | + if (isset($options['HTTPHEADER'])) { |
|
152 | + if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
153 | + $bodyData = $body; |
|
155 | 154 | } |
156 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); |
|
157 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
158 | 155 | } |
159 | - break; |
|
156 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); |
|
157 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
158 | + } |
|
159 | + break; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
@@ -7,374 +7,374 @@ |
||
7 | 7 | |
8 | 8 | class Route4Me |
9 | 9 | { |
10 | - public static $apiKey; |
|
11 | - public static $baseUrl = Endpoint::BASE_URL; |
|
12 | - |
|
13 | - public static function setApiKey($apiKey) |
|
14 | - { |
|
15 | - self::$apiKey = $apiKey; |
|
16 | - } |
|
17 | - |
|
18 | - public static function getApiKey() |
|
19 | - { |
|
20 | - return self::$apiKey; |
|
21 | - } |
|
22 | - |
|
23 | - public static function setBaseUrl($baseUrl) |
|
24 | - { |
|
25 | - self::$baseUrl = $baseUrl; |
|
26 | - } |
|
27 | - |
|
28 | - public static function getBaseUrl() |
|
29 | - { |
|
30 | - return self::$baseUrl; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Make request with CURL |
|
35 | - * |
|
36 | - * @since 1.2.3 changed error handling |
|
37 | - * @since 1.2.8 added $options['return_headers'] |
|
38 | - * |
|
39 | - * @param array $options |
|
40 | - * string url - HTTP URL. |
|
41 | - * string method - HTTP method. |
|
42 | - * string api_key - API key to access to route4me server. |
|
43 | - * array query - Array of query parameters. |
|
44 | - * array body - Array of body parameters. |
|
45 | - * string HTTPHEADER - Content type of body e.g. |
|
46 | - * 'Content-Type: application/json' |
|
47 | - * 'Content-Type: multipart/form-data' |
|
48 | - * array HTTPHEADERS - Array of headers. |
|
49 | - * string FILE - Path to uploading file. |
|
50 | - * array return_headers - Array of response headers to return as a result. |
|
51 | - * @throws Exception\ApiError |
|
52 | - */ |
|
53 | - public static function makeRequst($options) |
|
54 | - { |
|
55 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
56 | - $query = isset($options['query']) |
|
57 | - ? array_filter($options['query'], function ($x) { |
|
58 | - return !is_null($x); |
|
59 | - }) : []; |
|
60 | - |
|
61 | - $body = isset($options['body']) ? $options['body'] : null; |
|
62 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
63 | - $headers = [ |
|
64 | - 'User-Agent: Route4Me php-sdk', |
|
65 | - ]; |
|
66 | - |
|
67 | - $return_headers = (isset($options['return_headers']) ? $options['return_headers'] : null); |
|
68 | - |
|
69 | - if (isset($options['HTTPHEADER'])) { |
|
70 | - $headers[] = $options['HTTPHEADER']; |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($options['HTTPHEADERS'])) { |
|
74 | - foreach ($options['HTTPHEADERS'] as $header) { |
|
75 | - $headers[] = $header; |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - $ch = curl_init(); |
|
80 | - |
|
81 | - $url = isset($options['url']) |
|
82 | - ? $options['url'] . '?' . http_build_query(array_merge( |
|
83 | - $query, |
|
84 | - ['api_key' => self::getApiKey()] |
|
85 | - )) : ''; |
|
86 | - |
|
87 | - $baseUrl = self::getBaseUrl(); |
|
88 | - |
|
89 | - $curlOpts = [ |
|
90 | - CURLOPT_URL => $baseUrl.$url, |
|
91 | - CURLOPT_RETURNTRANSFER => true, |
|
92 | - CURLOPT_TIMEOUT => 120, |
|
93 | - CURLOPT_FOLLOWLOCATION => true, |
|
94 | - CURLOPT_SSL_VERIFYHOST => false, |
|
95 | - CURLOPT_SSL_VERIFYPEER => false, |
|
96 | - CURLOPT_HTTPHEADER => $headers, |
|
97 | - ]; |
|
98 | - |
|
99 | - curl_setopt_array($ch, $curlOpts); |
|
100 | - |
|
101 | - // read response headers if need |
|
102 | - $response_headers = []; |
|
103 | - if ($return_headers) { |
|
104 | - curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$response_headers) { |
|
105 | - $len = strlen($header); |
|
106 | - $header = explode(':', $header, 2); |
|
107 | - if (count($header) >= 2) { |
|
108 | - $response_headers[strtolower(trim($header[0]))] = trim($header[1]); |
|
109 | - } |
|
110 | - return $len; |
|
111 | - }); |
|
112 | - } |
|
113 | - |
|
114 | - if (null != $file) { |
|
115 | - $cfile = new \CURLFile($file, '', ''); |
|
116 | - $body['strFilename']=$cfile; |
|
117 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
118 | - curl_setopt($ch, CURLOPT_POST, true); |
|
119 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
|
120 | - } else { |
|
121 | - switch ($method) { |
|
122 | - case 'DELETE': |
|
123 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
124 | - break; |
|
125 | - case 'DELETEARRAY': |
|
126 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
127 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
128 | - break; |
|
129 | - case 'PUT': |
|
130 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
131 | - break; |
|
132 | - case 'POST': |
|
133 | - if (isset($body)) { |
|
134 | - if (isset($options['HTTPHEADER']) |
|
135 | - && strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
136 | - $bodyData = $body; |
|
137 | - } else { |
|
138 | - $bodyData = json_encode($body); |
|
139 | - } |
|
140 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
141 | - curl_setopt($ch, CURLOPT_POSTREDIR, 7); |
|
142 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
143 | - } |
|
144 | - break; |
|
145 | - case 'ADD': |
|
146 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
147 | - break; |
|
148 | - case 'PATCH': |
|
149 | - if (isset($body)) { |
|
150 | - $bodyData = json_encode($body); |
|
151 | - if (isset($options['HTTPHEADER'])) { |
|
152 | - if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
153 | - $bodyData = $body; |
|
154 | - } |
|
155 | - } |
|
156 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); |
|
157 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
158 | - } |
|
159 | - break; |
|
160 | - } |
|
161 | - |
|
162 | - if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
|
163 | - if (isset($body)) { |
|
164 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - $result = curl_exec($ch); |
|
170 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
171 | - curl_close($ch); |
|
172 | - |
|
173 | - $json = null; |
|
174 | - if (strpos($result, '<?xml') > -1) { |
|
175 | - $xml = simplexml_load_string($result); |
|
176 | - $json = self::object2array($xml); |
|
177 | - } else { |
|
178 | - $json = json_decode($result, true); |
|
179 | - } |
|
180 | - if (200 == $code || 201 == $code || 202 == $code || 204 == $code) { |
|
181 | - if (isset($json['errors'])) { |
|
182 | - throw new ApiError(implode(', ', $json['errors']), $code, $result); |
|
183 | - } else { |
|
184 | - // return response headers if they were asked for |
|
185 | - if (count($response_headers) !== 0) { |
|
186 | - $res = [ |
|
187 | - 'code' => $code, |
|
188 | - 'data' => $json |
|
189 | - ]; |
|
190 | - foreach ($return_headers as $key => $value) { |
|
191 | - // most headers has char '-' but it is forbidden in PHP names replace it with '_' |
|
192 | - $res[strtolower(str_replace('-', '_', $value))] = |
|
193 | - (isset($response_headers[$value]) ? $response_headers[$value] : null); |
|
194 | - } |
|
195 | - return $res; |
|
196 | - } |
|
197 | - if (204 == $code) { |
|
198 | - return true; |
|
199 | - } |
|
200 | - return $json; |
|
201 | - } |
|
202 | - } elseif (isset($code) && (!isset($result) || !$result)) { |
|
203 | - throw new ApiError('', $code, $result); |
|
204 | - } else { |
|
205 | - if (isset($json['messages'])) { |
|
206 | - $msg = ''; |
|
207 | - foreach ($json['messages'] as $key => $value) { |
|
208 | - if ($msg !== '') { |
|
209 | - $msg .= PHP_EOL; |
|
210 | - } |
|
211 | - $msg .= $key . ': ' . (is_array($value) ? implode(', ', $value) : $value); |
|
212 | - } |
|
213 | - throw new ApiError($msg, $code, $result); |
|
214 | - } elseif (isset($json['error']) && !empty($json['error'])) { |
|
215 | - throw new ApiError($json['error'], $code, $result); |
|
216 | - } elseif (isset($json['error'])) { |
|
217 | - $msg = ''; |
|
218 | - foreach ($json['errors'] as $key => $value) { |
|
219 | - if ($msg !== '') { |
|
220 | - $msg .= PHP_EOL; |
|
221 | - } |
|
222 | - $msg .= $value; |
|
223 | - } |
|
224 | - throw new ApiError($msg, $code, $result); |
|
225 | - } else { |
|
226 | - throw new ApiError($result, $code, $result); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * @param $object: JSON object |
|
233 | - */ |
|
234 | - public static function object2array($object) |
|
235 | - { |
|
236 | - return @json_decode(@json_encode($object), 1); |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Prints on the screen main keys and values of the array. |
|
241 | - * |
|
242 | - * @param $results: object to be printed on the screen |
|
243 | - * @param $deepPrinting: if true, object will be printed recursively |
|
244 | - */ |
|
245 | - public static function simplePrint($results, $deepPrinting = null) |
|
246 | - { |
|
247 | - if (isset($results)) { |
|
248 | - if (is_array($results)) { |
|
249 | - foreach ($results as $key => $result) { |
|
250 | - if (is_array($result)) { |
|
251 | - foreach ($result as $key1 => $result1) { |
|
252 | - if (is_array($result1)) { |
|
253 | - if ($deepPrinting) { |
|
254 | - echo "<br>$key1 ------><br>"; |
|
255 | - self::simplePrint($result1, true); |
|
256 | - echo '------<br>'; |
|
257 | - } else { |
|
258 | - echo $key1.' --> '.'Array() <br>'; |
|
259 | - } |
|
260 | - } else { |
|
261 | - if (is_object($result1)) { |
|
262 | - if ($deepPrinting) { |
|
263 | - echo "<br>$key1 ------><br>"; |
|
264 | - $oarray = (array) $result1; |
|
265 | - self::simplePrint($oarray, true); |
|
266 | - echo '------<br>'; |
|
267 | - } else { |
|
268 | - echo $key1.' --> '.'Object <br>'; |
|
269 | - } |
|
270 | - } else { |
|
271 | - if (!is_null($result1)) { |
|
272 | - echo $key1.' --> '.$result1.'<br>'; |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - } |
|
277 | - } else { |
|
278 | - if (is_object($result)) { |
|
279 | - if ($deepPrinting) { |
|
280 | - echo "<br>$key ------><br>"; |
|
281 | - $oarray = (array) $result; |
|
282 | - self::simplePrint($oarray, true); |
|
283 | - echo '------<br>'; |
|
284 | - } else { |
|
285 | - echo $key.' --> '.'Object <br>'; |
|
286 | - } |
|
287 | - } else { |
|
288 | - if (!is_null($result)) { |
|
289 | - echo $key.' --> '.$result.'<br>'; |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
293 | - //echo "<br>"; |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Generates query or body parameters. |
|
301 | - * |
|
302 | - * @param $allFields: all known fields could be used for parameters generation |
|
303 | - * @param $params: input parameters (array or object) |
|
304 | - */ |
|
305 | - public static function generateRequestParameters($allFields, $params) |
|
306 | - { |
|
307 | - $generatedParams = []; |
|
308 | - |
|
309 | - if (is_array($params)) { |
|
310 | - foreach ($allFields as $field) { |
|
311 | - if (isset($params[$field])) { |
|
312 | - $generatedParams[$field] = $params[$field]; |
|
313 | - } |
|
314 | - } |
|
315 | - } elseif (is_object($params)) { |
|
316 | - foreach ($allFields as $field) { |
|
317 | - if (isset($params->{$field})) { |
|
318 | - $generatedParams[$field] = $params->{$field}; |
|
319 | - } |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - return $generatedParams; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Returns an array of the object properties. |
|
328 | - * |
|
329 | - * @param $object: An object |
|
330 | - * @param $exclude: array of the object parameters to be excluded from the returned array |
|
331 | - */ |
|
332 | - public static function getObjectProperties($object, $exclude) |
|
333 | - { |
|
334 | - $objectParameters = []; |
|
335 | - |
|
336 | - foreach (get_object_vars($object) as $key => $value) { |
|
337 | - if (property_exists($object, $key)) { |
|
338 | - if (!is_numeric(array_search($key, $exclude))) { |
|
339 | - array_push($objectParameters, $key); |
|
340 | - } |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - return $objectParameters; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Returns url path generated from the array of the fields and parameters. |
|
349 | - * |
|
350 | - * @param $allFields; array of the paossible fields (parameter names) |
|
351 | - * @param $params: input parameters (array or object) |
|
352 | - */ |
|
353 | - public static function generateUrlPath($allFields, $params) |
|
354 | - { |
|
355 | - $generatedPath = ''; |
|
356 | - |
|
357 | - if (is_array($params)) { |
|
358 | - foreach ($allFields as $field) { |
|
359 | - if (isset($params[$field])) { |
|
360 | - $generatedPath .= $params[$field].'/'; |
|
361 | - } |
|
362 | - } |
|
363 | - } elseif (is_object($params)) { |
|
364 | - foreach ($allFields as $field) { |
|
365 | - if (isset($params->{$field})) { |
|
366 | - $generatedPath .= $params->{$field}.'/'; |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - return $generatedPath; |
|
372 | - } |
|
373 | - |
|
374 | - public static function getFileRealPath($fileName) |
|
375 | - { |
|
376 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
377 | - |
|
378 | - return $rpath; |
|
379 | - } |
|
10 | + public static $apiKey; |
|
11 | + public static $baseUrl = Endpoint::BASE_URL; |
|
12 | + |
|
13 | + public static function setApiKey($apiKey) |
|
14 | + { |
|
15 | + self::$apiKey = $apiKey; |
|
16 | + } |
|
17 | + |
|
18 | + public static function getApiKey() |
|
19 | + { |
|
20 | + return self::$apiKey; |
|
21 | + } |
|
22 | + |
|
23 | + public static function setBaseUrl($baseUrl) |
|
24 | + { |
|
25 | + self::$baseUrl = $baseUrl; |
|
26 | + } |
|
27 | + |
|
28 | + public static function getBaseUrl() |
|
29 | + { |
|
30 | + return self::$baseUrl; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Make request with CURL |
|
35 | + * |
|
36 | + * @since 1.2.3 changed error handling |
|
37 | + * @since 1.2.8 added $options['return_headers'] |
|
38 | + * |
|
39 | + * @param array $options |
|
40 | + * string url - HTTP URL. |
|
41 | + * string method - HTTP method. |
|
42 | + * string api_key - API key to access to route4me server. |
|
43 | + * array query - Array of query parameters. |
|
44 | + * array body - Array of body parameters. |
|
45 | + * string HTTPHEADER - Content type of body e.g. |
|
46 | + * 'Content-Type: application/json' |
|
47 | + * 'Content-Type: multipart/form-data' |
|
48 | + * array HTTPHEADERS - Array of headers. |
|
49 | + * string FILE - Path to uploading file. |
|
50 | + * array return_headers - Array of response headers to return as a result. |
|
51 | + * @throws Exception\ApiError |
|
52 | + */ |
|
53 | + public static function makeRequst($options) |
|
54 | + { |
|
55 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
56 | + $query = isset($options['query']) |
|
57 | + ? array_filter($options['query'], function ($x) { |
|
58 | + return !is_null($x); |
|
59 | + }) : []; |
|
60 | + |
|
61 | + $body = isset($options['body']) ? $options['body'] : null; |
|
62 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
63 | + $headers = [ |
|
64 | + 'User-Agent: Route4Me php-sdk', |
|
65 | + ]; |
|
66 | + |
|
67 | + $return_headers = (isset($options['return_headers']) ? $options['return_headers'] : null); |
|
68 | + |
|
69 | + if (isset($options['HTTPHEADER'])) { |
|
70 | + $headers[] = $options['HTTPHEADER']; |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($options['HTTPHEADERS'])) { |
|
74 | + foreach ($options['HTTPHEADERS'] as $header) { |
|
75 | + $headers[] = $header; |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + $ch = curl_init(); |
|
80 | + |
|
81 | + $url = isset($options['url']) |
|
82 | + ? $options['url'] . '?' . http_build_query(array_merge( |
|
83 | + $query, |
|
84 | + ['api_key' => self::getApiKey()] |
|
85 | + )) : ''; |
|
86 | + |
|
87 | + $baseUrl = self::getBaseUrl(); |
|
88 | + |
|
89 | + $curlOpts = [ |
|
90 | + CURLOPT_URL => $baseUrl.$url, |
|
91 | + CURLOPT_RETURNTRANSFER => true, |
|
92 | + CURLOPT_TIMEOUT => 120, |
|
93 | + CURLOPT_FOLLOWLOCATION => true, |
|
94 | + CURLOPT_SSL_VERIFYHOST => false, |
|
95 | + CURLOPT_SSL_VERIFYPEER => false, |
|
96 | + CURLOPT_HTTPHEADER => $headers, |
|
97 | + ]; |
|
98 | + |
|
99 | + curl_setopt_array($ch, $curlOpts); |
|
100 | + |
|
101 | + // read response headers if need |
|
102 | + $response_headers = []; |
|
103 | + if ($return_headers) { |
|
104 | + curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$response_headers) { |
|
105 | + $len = strlen($header); |
|
106 | + $header = explode(':', $header, 2); |
|
107 | + if (count($header) >= 2) { |
|
108 | + $response_headers[strtolower(trim($header[0]))] = trim($header[1]); |
|
109 | + } |
|
110 | + return $len; |
|
111 | + }); |
|
112 | + } |
|
113 | + |
|
114 | + if (null != $file) { |
|
115 | + $cfile = new \CURLFile($file, '', ''); |
|
116 | + $body['strFilename']=$cfile; |
|
117 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
118 | + curl_setopt($ch, CURLOPT_POST, true); |
|
119 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
|
120 | + } else { |
|
121 | + switch ($method) { |
|
122 | + case 'DELETE': |
|
123 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
124 | + break; |
|
125 | + case 'DELETEARRAY': |
|
126 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
127 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
128 | + break; |
|
129 | + case 'PUT': |
|
130 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
131 | + break; |
|
132 | + case 'POST': |
|
133 | + if (isset($body)) { |
|
134 | + if (isset($options['HTTPHEADER']) |
|
135 | + && strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
136 | + $bodyData = $body; |
|
137 | + } else { |
|
138 | + $bodyData = json_encode($body); |
|
139 | + } |
|
140 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
141 | + curl_setopt($ch, CURLOPT_POSTREDIR, 7); |
|
142 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
143 | + } |
|
144 | + break; |
|
145 | + case 'ADD': |
|
146 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
147 | + break; |
|
148 | + case 'PATCH': |
|
149 | + if (isset($body)) { |
|
150 | + $bodyData = json_encode($body); |
|
151 | + if (isset($options['HTTPHEADER'])) { |
|
152 | + if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
153 | + $bodyData = $body; |
|
154 | + } |
|
155 | + } |
|
156 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); |
|
157 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
158 | + } |
|
159 | + break; |
|
160 | + } |
|
161 | + |
|
162 | + if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
|
163 | + if (isset($body)) { |
|
164 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + $result = curl_exec($ch); |
|
170 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
171 | + curl_close($ch); |
|
172 | + |
|
173 | + $json = null; |
|
174 | + if (strpos($result, '<?xml') > -1) { |
|
175 | + $xml = simplexml_load_string($result); |
|
176 | + $json = self::object2array($xml); |
|
177 | + } else { |
|
178 | + $json = json_decode($result, true); |
|
179 | + } |
|
180 | + if (200 == $code || 201 == $code || 202 == $code || 204 == $code) { |
|
181 | + if (isset($json['errors'])) { |
|
182 | + throw new ApiError(implode(', ', $json['errors']), $code, $result); |
|
183 | + } else { |
|
184 | + // return response headers if they were asked for |
|
185 | + if (count($response_headers) !== 0) { |
|
186 | + $res = [ |
|
187 | + 'code' => $code, |
|
188 | + 'data' => $json |
|
189 | + ]; |
|
190 | + foreach ($return_headers as $key => $value) { |
|
191 | + // most headers has char '-' but it is forbidden in PHP names replace it with '_' |
|
192 | + $res[strtolower(str_replace('-', '_', $value))] = |
|
193 | + (isset($response_headers[$value]) ? $response_headers[$value] : null); |
|
194 | + } |
|
195 | + return $res; |
|
196 | + } |
|
197 | + if (204 == $code) { |
|
198 | + return true; |
|
199 | + } |
|
200 | + return $json; |
|
201 | + } |
|
202 | + } elseif (isset($code) && (!isset($result) || !$result)) { |
|
203 | + throw new ApiError('', $code, $result); |
|
204 | + } else { |
|
205 | + if (isset($json['messages'])) { |
|
206 | + $msg = ''; |
|
207 | + foreach ($json['messages'] as $key => $value) { |
|
208 | + if ($msg !== '') { |
|
209 | + $msg .= PHP_EOL; |
|
210 | + } |
|
211 | + $msg .= $key . ': ' . (is_array($value) ? implode(', ', $value) : $value); |
|
212 | + } |
|
213 | + throw new ApiError($msg, $code, $result); |
|
214 | + } elseif (isset($json['error']) && !empty($json['error'])) { |
|
215 | + throw new ApiError($json['error'], $code, $result); |
|
216 | + } elseif (isset($json['error'])) { |
|
217 | + $msg = ''; |
|
218 | + foreach ($json['errors'] as $key => $value) { |
|
219 | + if ($msg !== '') { |
|
220 | + $msg .= PHP_EOL; |
|
221 | + } |
|
222 | + $msg .= $value; |
|
223 | + } |
|
224 | + throw new ApiError($msg, $code, $result); |
|
225 | + } else { |
|
226 | + throw new ApiError($result, $code, $result); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * @param $object: JSON object |
|
233 | + */ |
|
234 | + public static function object2array($object) |
|
235 | + { |
|
236 | + return @json_decode(@json_encode($object), 1); |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Prints on the screen main keys and values of the array. |
|
241 | + * |
|
242 | + * @param $results: object to be printed on the screen |
|
243 | + * @param $deepPrinting: if true, object will be printed recursively |
|
244 | + */ |
|
245 | + public static function simplePrint($results, $deepPrinting = null) |
|
246 | + { |
|
247 | + if (isset($results)) { |
|
248 | + if (is_array($results)) { |
|
249 | + foreach ($results as $key => $result) { |
|
250 | + if (is_array($result)) { |
|
251 | + foreach ($result as $key1 => $result1) { |
|
252 | + if (is_array($result1)) { |
|
253 | + if ($deepPrinting) { |
|
254 | + echo "<br>$key1 ------><br>"; |
|
255 | + self::simplePrint($result1, true); |
|
256 | + echo '------<br>'; |
|
257 | + } else { |
|
258 | + echo $key1.' --> '.'Array() <br>'; |
|
259 | + } |
|
260 | + } else { |
|
261 | + if (is_object($result1)) { |
|
262 | + if ($deepPrinting) { |
|
263 | + echo "<br>$key1 ------><br>"; |
|
264 | + $oarray = (array) $result1; |
|
265 | + self::simplePrint($oarray, true); |
|
266 | + echo '------<br>'; |
|
267 | + } else { |
|
268 | + echo $key1.' --> '.'Object <br>'; |
|
269 | + } |
|
270 | + } else { |
|
271 | + if (!is_null($result1)) { |
|
272 | + echo $key1.' --> '.$result1.'<br>'; |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + } |
|
277 | + } else { |
|
278 | + if (is_object($result)) { |
|
279 | + if ($deepPrinting) { |
|
280 | + echo "<br>$key ------><br>"; |
|
281 | + $oarray = (array) $result; |
|
282 | + self::simplePrint($oarray, true); |
|
283 | + echo '------<br>'; |
|
284 | + } else { |
|
285 | + echo $key.' --> '.'Object <br>'; |
|
286 | + } |
|
287 | + } else { |
|
288 | + if (!is_null($result)) { |
|
289 | + echo $key.' --> '.$result.'<br>'; |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | + //echo "<br>"; |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Generates query or body parameters. |
|
301 | + * |
|
302 | + * @param $allFields: all known fields could be used for parameters generation |
|
303 | + * @param $params: input parameters (array or object) |
|
304 | + */ |
|
305 | + public static function generateRequestParameters($allFields, $params) |
|
306 | + { |
|
307 | + $generatedParams = []; |
|
308 | + |
|
309 | + if (is_array($params)) { |
|
310 | + foreach ($allFields as $field) { |
|
311 | + if (isset($params[$field])) { |
|
312 | + $generatedParams[$field] = $params[$field]; |
|
313 | + } |
|
314 | + } |
|
315 | + } elseif (is_object($params)) { |
|
316 | + foreach ($allFields as $field) { |
|
317 | + if (isset($params->{$field})) { |
|
318 | + $generatedParams[$field] = $params->{$field}; |
|
319 | + } |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + return $generatedParams; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Returns an array of the object properties. |
|
328 | + * |
|
329 | + * @param $object: An object |
|
330 | + * @param $exclude: array of the object parameters to be excluded from the returned array |
|
331 | + */ |
|
332 | + public static function getObjectProperties($object, $exclude) |
|
333 | + { |
|
334 | + $objectParameters = []; |
|
335 | + |
|
336 | + foreach (get_object_vars($object) as $key => $value) { |
|
337 | + if (property_exists($object, $key)) { |
|
338 | + if (!is_numeric(array_search($key, $exclude))) { |
|
339 | + array_push($objectParameters, $key); |
|
340 | + } |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + return $objectParameters; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Returns url path generated from the array of the fields and parameters. |
|
349 | + * |
|
350 | + * @param $allFields; array of the paossible fields (parameter names) |
|
351 | + * @param $params: input parameters (array or object) |
|
352 | + */ |
|
353 | + public static function generateUrlPath($allFields, $params) |
|
354 | + { |
|
355 | + $generatedPath = ''; |
|
356 | + |
|
357 | + if (is_array($params)) { |
|
358 | + foreach ($allFields as $field) { |
|
359 | + if (isset($params[$field])) { |
|
360 | + $generatedPath .= $params[$field].'/'; |
|
361 | + } |
|
362 | + } |
|
363 | + } elseif (is_object($params)) { |
|
364 | + foreach ($allFields as $field) { |
|
365 | + if (isset($params->{$field})) { |
|
366 | + $generatedPath .= $params->{$field}.'/'; |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + return $generatedPath; |
|
372 | + } |
|
373 | + |
|
374 | + public static function getFileRealPath($fileName) |
|
375 | + { |
|
376 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
377 | + |
|
378 | + return $rpath; |
|
379 | + } |
|
380 | 380 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | $method = isset($options['method']) ? $options['method'] : 'GET'; |
56 | 56 | $query = isset($options['query']) |
57 | - ? array_filter($options['query'], function ($x) { |
|
57 | + ? array_filter($options['query'], function($x) { |
|
58 | 58 | return !is_null($x); |
59 | 59 | }) : []; |
60 | 60 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $ch = curl_init(); |
80 | 80 | |
81 | 81 | $url = isset($options['url']) |
82 | - ? $options['url'] . '?' . http_build_query(array_merge( |
|
82 | + ? $options['url'].'?'.http_build_query(array_merge( |
|
83 | 83 | $query, |
84 | 84 | ['api_key' => self::getApiKey()] |
85 | 85 | )) : ''; |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | // read response headers if need |
102 | 102 | $response_headers = []; |
103 | 103 | if ($return_headers) { |
104 | - curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$response_headers) { |
|
104 | + curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $header) use (&$response_headers) { |
|
105 | 105 | $len = strlen($header); |
106 | 106 | $header = explode(':', $header, 2); |
107 | - if (count($header) >= 2) { |
|
107 | + if (count($header)>=2) { |
|
108 | 108 | $response_headers[strtolower(trim($header[0]))] = trim($header[1]); |
109 | 109 | } |
110 | 110 | return $len; |
111 | 111 | }); |
112 | 112 | } |
113 | 113 | |
114 | - if (null != $file) { |
|
114 | + if (null!=$file) { |
|
115 | 115 | $cfile = new \CURLFile($file, '', ''); |
116 | - $body['strFilename']=$cfile; |
|
116 | + $body['strFilename'] = $cfile; |
|
117 | 117 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
118 | 118 | curl_setopt($ch, CURLOPT_POST, true); |
119 | 119 | curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | case 'POST': |
133 | 133 | if (isset($body)) { |
134 | 134 | if (isset($options['HTTPHEADER']) |
135 | - && strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
135 | + && strpos($options['HTTPHEADER'], 'multipart/form-data')>0) { |
|
136 | 136 | $bodyData = $body; |
137 | 137 | } else { |
138 | 138 | $bodyData = json_encode($body); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | if (isset($body)) { |
150 | 150 | $bodyData = json_encode($body); |
151 | 151 | if (isset($options['HTTPHEADER'])) { |
152 | - if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
152 | + if (strpos($options['HTTPHEADER'], 'multipart/form-data')>0) { |
|
153 | 153 | $bodyData = $body; |
154 | 154 | } |
155 | 155 | } |
@@ -171,18 +171,18 @@ discard block |
||
171 | 171 | curl_close($ch); |
172 | 172 | |
173 | 173 | $json = null; |
174 | - if (strpos($result, '<?xml') > -1) { |
|
174 | + if (strpos($result, '<?xml')>-1) { |
|
175 | 175 | $xml = simplexml_load_string($result); |
176 | 176 | $json = self::object2array($xml); |
177 | 177 | } else { |
178 | 178 | $json = json_decode($result, true); |
179 | 179 | } |
180 | - if (200 == $code || 201 == $code || 202 == $code || 204 == $code) { |
|
180 | + if (200==$code || 201==$code || 202==$code || 204==$code) { |
|
181 | 181 | if (isset($json['errors'])) { |
182 | 182 | throw new ApiError(implode(', ', $json['errors']), $code, $result); |
183 | 183 | } else { |
184 | 184 | // return response headers if they were asked for |
185 | - if (count($response_headers) !== 0) { |
|
185 | + if (count($response_headers)!==0) { |
|
186 | 186 | $res = [ |
187 | 187 | 'code' => $code, |
188 | 188 | 'data' => $json |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | } |
195 | 195 | return $res; |
196 | 196 | } |
197 | - if (204 == $code) { |
|
197 | + if (204==$code) { |
|
198 | 198 | return true; |
199 | 199 | } |
200 | 200 | return $json; |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | if (isset($json['messages'])) { |
206 | 206 | $msg = ''; |
207 | 207 | foreach ($json['messages'] as $key => $value) { |
208 | - if ($msg !== '') { |
|
208 | + if ($msg!=='') { |
|
209 | 209 | $msg .= PHP_EOL; |
210 | 210 | } |
211 | - $msg .= $key . ': ' . (is_array($value) ? implode(', ', $value) : $value); |
|
211 | + $msg .= $key.': '.(is_array($value) ? implode(', ', $value) : $value); |
|
212 | 212 | } |
213 | 213 | throw new ApiError($msg, $code, $result); |
214 | 214 | } elseif (isset($json['error']) && !empty($json['error'])) { |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | } elseif (isset($json['error'])) { |
217 | 217 | $msg = ''; |
218 | 218 | foreach ($json['errors'] as $key => $value) { |
219 | - if ($msg !== '') { |
|
219 | + if ($msg!=='') { |
|
220 | 220 | $msg .= PHP_EOL; |
221 | 221 | } |
222 | 222 | $msg .= $value; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | if (is_object($result1)) { |
262 | 262 | if ($deepPrinting) { |
263 | 263 | echo "<br>$key1 ------><br>"; |
264 | - $oarray = (array) $result1; |
|
264 | + $oarray = (array)$result1; |
|
265 | 265 | self::simplePrint($oarray, true); |
266 | 266 | echo '------<br>'; |
267 | 267 | } else { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | if (is_object($result)) { |
279 | 279 | if ($deepPrinting) { |
280 | 280 | echo "<br>$key ------><br>"; |
281 | - $oarray = (array) $result; |
|
281 | + $oarray = (array)$result; |
|
282 | 282 | self::simplePrint($oarray, true); |
283 | 283 | echo '------<br>'; |
284 | 284 | } else { |