@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | |
26 | 26 | if (isset($addressRand['is_depot'])) |
27 | 27 | { |
28 | - if ($addressRand['is_depot']) { |
|
29 | - echo "Random choosed address is depot, it can't be marked!.. Try again."; |
|
30 | - return; |
|
31 | - } |
|
28 | + if ($addressRand['is_depot']) { |
|
29 | + echo "Random choosed address is depot, it can't be marked!.. Try again."; |
|
30 | + return; |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $address_id = $addressRand['route_destination_id']; |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | |
38 | 38 | // Mark the address as detected as visited |
39 | 39 | $addressParameters = (array)Address::fromArray(array( |
40 | - "route_id" => $routeId, |
|
41 | - "route_destination_id" => $address_id, |
|
42 | - "is_visited" => TRUE |
|
40 | + "route_id" => $routeId, |
|
41 | + "route_destination_id" => $address_id, |
|
42 | + "is_visited" => TRUE |
|
43 | 43 | )); |
44 | 44 | |
45 | 45 | $address = new Address(); |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | |
26 | 26 | if (isset($addressRand['is_depot'])) |
27 | 27 | { |
28 | - if ($addressRand['is_depot']) { |
|
29 | - echo "Random choosed address is depot, it can't be marked!.. Try again."; |
|
30 | - return; |
|
31 | - } |
|
28 | + if ($addressRand['is_depot']) { |
|
29 | + echo "Random choosed address is depot, it can't be marked!.. Try again."; |
|
30 | + return; |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | // Get random address's id from selected route above |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | |
40 | 40 | // Mark the address as detected as deoarted |
41 | 41 | $addressParameters = (array)Address::fromArray(array( |
42 | - "route_id" => $routeId, |
|
43 | - "route_destination_id" => $route_destination_id, |
|
44 | - "is_departed" => TRUE |
|
42 | + "route_id" => $routeId, |
|
43 | + "route_destination_id" => $route_destination_id, |
|
44 | + "is_departed" => TRUE |
|
45 | 45 | )); |
46 | 46 | |
47 | 47 | $address = new Address(); |
@@ -19,8 +19,8 @@ |
||
19 | 19 | assert(!is_null($route_id), "Can't retrieve a random route ID"); |
20 | 20 | |
21 | 21 | $params = array( |
22 | - 'device_tracking_history' => true, |
|
23 | - 'route_id' => $route_id |
|
22 | + 'device_tracking_history' => true, |
|
23 | + 'route_id' => $route_id |
|
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Get route tracking |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | |
19 | 19 | // Select a route with more than 4 addresses. |
20 | 20 | $routesParams = array( |
21 | - "offset" => 0, |
|
22 | - "limit" => 20 |
|
21 | + "offset" => 0, |
|
22 | + "limit" => 20 |
|
23 | 23 | ); |
24 | 24 | |
25 | 25 | $routes = $route->getRoutes($routesParams); |
@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | $selectedRoute = null; |
28 | 28 | |
29 | 29 | foreach ($routes as $route1) { |
30 | - if (isset($route1->destination_count)) { |
|
31 | - if ($route1->destination_count>4) { |
|
32 | - $selectedRoute = $route->getRoutes(array('route_id' => $route1->route_id)); |
|
33 | - break; |
|
34 | - } |
|
35 | - } |
|
30 | + if (isset($route1->destination_count)) { |
|
31 | + if ($route1->destination_count>4) { |
|
32 | + $selectedRoute = $route->getRoutes(array('route_id' => $route1->route_id)); |
|
33 | + break; |
|
34 | + } |
|
35 | + } |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | assert(!is_null($selectedRoute), "Can't select a route with more than 4 addresses"); |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | echo "Route ID-> $routeID, Route destination ID -> $routeDestinationID <br>"; |
45 | 45 | |
46 | 46 | $params = array( |
47 | - "route_id" => $routeID, |
|
48 | - "route_destination_id" => $routeDestinationID, |
|
49 | - "addresses" => array( |
|
50 | - "0" => array( |
|
51 | - "route_destination_id" => $routeDestinationID, |
|
52 | - "sequence_no" => 3 |
|
53 | - ) |
|
54 | - ) |
|
47 | + "route_id" => $routeID, |
|
48 | + "route_destination_id" => $routeDestinationID, |
|
49 | + "addresses" => array( |
|
50 | + "0" => array( |
|
51 | + "route_destination_id" => $routeDestinationID, |
|
52 | + "sequence_no" => 3 |
|
53 | + ) |
|
54 | + ) |
|
55 | 55 | ); |
56 | 56 | |
57 | 57 | $response = $route->resequenceRoute($params); |
58 | 58 | |
59 | 59 | foreach ($response['addresses'] as $address) { |
60 | - Route4Me::simplePrint($address); |
|
61 | - echo "<br>"; |
|
60 | + Route4Me::simplePrint($address); |
|
61 | + echo "<br>"; |
|
62 | 62 | } |
@@ -23,8 +23,8 @@ |
||
23 | 23 | |
24 | 24 | // Get a route with the directions |
25 | 25 | $params = array( |
26 | - "directions" => 1, |
|
27 | - "route_id" => $route_id |
|
26 | + "directions" => 1, |
|
27 | + "route_id" => $route_id |
|
28 | 28 | ); |
29 | 29 | |
30 | 30 | $routeResults = (array)$route->getRoutePoints($params); |
@@ -7,16 +7,16 @@ |
||
7 | 7 | |
8 | 8 | class Track extends Common |
9 | 9 | { |
10 | - public static function set(TrackSetParams $params) |
|
11 | - { |
|
12 | - $allQueryFields = Route4Me::getObjectProperties(new TrackSetParams(), array('tx_id')); |
|
10 | + public static function set(TrackSetParams $params) |
|
11 | + { |
|
12 | + $allQueryFields = Route4Me::getObjectProperties(new TrackSetParams(), array('tx_id')); |
|
13 | 13 | |
14 | - $json = Route4Me::makeRequst(array( |
|
15 | - 'url' => Endpoint::TRACK_SET, |
|
16 | - 'method' => 'GET', |
|
17 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
18 | - )); |
|
14 | + $json = Route4Me::makeRequst(array( |
|
15 | + 'url' => Endpoint::TRACK_SET, |
|
16 | + 'method' => 'GET', |
|
17 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
18 | + )); |
|
19 | 19 | |
20 | - return $json; |
|
21 | - } |
|
20 | + return $json; |
|
21 | + } |
|
22 | 22 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public static function getTerritory($params) |
42 | 42 | { |
43 | - $allQueryFields = array('territory_id', 'addresses'); |
|
43 | + $allQueryFields = array('territory_id', 'addresses'); |
|
44 | 44 | |
45 | 45 | $territory = Route4Me::makeRequst(array( |
46 | 46 | 'url' => Endpoint::TERRITORY_V4, |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public static function getTerritories($params) |
55 | 55 | { |
56 | - $allQueryFields = array('offset', 'limit', 'addresses'); |
|
56 | + $allQueryFields = array('offset', 'limit', 'addresses'); |
|
57 | 57 | |
58 | 58 | $response = Route4Me::makeRequst(array( |
59 | 59 | 'url' => Endpoint::TERRITORY_V4, |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | public static function addTerritory($params) |
68 | 68 | { |
69 | - $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
69 | + $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
70 | 70 | |
71 | 71 | $response = Route4Me::makeRequst(array( |
72 | 72 | 'url' => Endpoint::TERRITORY_V4, |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | |
93 | 93 | public function updateTerritory($params) |
94 | 94 | { |
95 | - $allQueryFields = array('territory_id'); |
|
96 | - $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
95 | + $allQueryFields = array('territory_id'); |
|
96 | + $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
97 | 97 | |
98 | 98 | $response = Route4Me::makeRequst(array( |
99 | 99 | 'url' => Endpoint::TERRITORY_V4, |
100 | 100 | 'method' => 'PUT', |
101 | 101 | 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
102 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
102 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
103 | 103 | )); |
104 | 104 | |
105 | 105 | return $response; |
@@ -6,157 +6,157 @@ |
||
6 | 6 | |
7 | 7 | class Vehicle extends Common |
8 | 8 | { |
9 | - public $vehicle_id; |
|
10 | - public $member_id; |
|
11 | - public $is_deleted; |
|
12 | - public $vehicle_alias; |
|
13 | - public $vehicle_vin; |
|
14 | - public $vehicle_reg_state_id; |
|
15 | - public $vehicle_reg_country_id; |
|
16 | - public $vehicle_license_plate; |
|
17 | - public $vehicle_type_id; |
|
18 | - public $vehicle_make; |
|
19 | - public $vehicle_model_year; |
|
20 | - public $vehicle_model; |
|
21 | - public $vehicle_year_acquired; |
|
22 | - public $vehicle_cost_new; |
|
23 | - public $purchased_new; |
|
24 | - public $license_start_date; |
|
25 | - public $license_end_date; |
|
26 | - public $vehicle_axle_count; |
|
27 | - public $is_operational; |
|
28 | - public $mpg_city; |
|
29 | - public $mpg_highway; |
|
30 | - public $fuel_type; |
|
31 | - public $height_inches; |
|
32 | - public $weight_lb; |
|
33 | - public $external_telematics_vehicle_id; |
|
34 | - public $has_trailer; |
|
35 | - public $heightInInches; |
|
36 | - public $lengthInInches; |
|
37 | - public $widthInInches; |
|
38 | - public $maxWeightPerAxleGroupInPounds; |
|
39 | - public $numAxles; |
|
40 | - public $weightInPounds; |
|
41 | - public $HazmatType; |
|
42 | - public $LowEmissionZonePref; |
|
43 | - public $Use53FootTrailerRouting; |
|
44 | - public $UseNationalNetwork; |
|
45 | - public $UseTruckRestrictions; |
|
46 | - public $AvoidFerries; |
|
47 | - public $DividedHighwayAvoidPreference; |
|
48 | - public $FreewayAvoidPreference; |
|
49 | - public $InternationalBordersOpen; |
|
50 | - public $TollRoadUsage; |
|
51 | - public $hwy_only; |
|
52 | - public $long_combination_vehicle; |
|
53 | - public $avoid_highways; |
|
54 | - public $side_street_adherence; |
|
55 | - public $truck_config; |
|
56 | - public $height_metric; |
|
57 | - public $length_metric; |
|
58 | - public $width_metric; |
|
59 | - public $weight_metric; |
|
60 | - public $max_weight_per_axle_group_metric; |
|
9 | + public $vehicle_id; |
|
10 | + public $member_id; |
|
11 | + public $is_deleted; |
|
12 | + public $vehicle_alias; |
|
13 | + public $vehicle_vin; |
|
14 | + public $vehicle_reg_state_id; |
|
15 | + public $vehicle_reg_country_id; |
|
16 | + public $vehicle_license_plate; |
|
17 | + public $vehicle_type_id; |
|
18 | + public $vehicle_make; |
|
19 | + public $vehicle_model_year; |
|
20 | + public $vehicle_model; |
|
21 | + public $vehicle_year_acquired; |
|
22 | + public $vehicle_cost_new; |
|
23 | + public $purchased_new; |
|
24 | + public $license_start_date; |
|
25 | + public $license_end_date; |
|
26 | + public $vehicle_axle_count; |
|
27 | + public $is_operational; |
|
28 | + public $mpg_city; |
|
29 | + public $mpg_highway; |
|
30 | + public $fuel_type; |
|
31 | + public $height_inches; |
|
32 | + public $weight_lb; |
|
33 | + public $external_telematics_vehicle_id; |
|
34 | + public $has_trailer; |
|
35 | + public $heightInInches; |
|
36 | + public $lengthInInches; |
|
37 | + public $widthInInches; |
|
38 | + public $maxWeightPerAxleGroupInPounds; |
|
39 | + public $numAxles; |
|
40 | + public $weightInPounds; |
|
41 | + public $HazmatType; |
|
42 | + public $LowEmissionZonePref; |
|
43 | + public $Use53FootTrailerRouting; |
|
44 | + public $UseNationalNetwork; |
|
45 | + public $UseTruckRestrictions; |
|
46 | + public $AvoidFerries; |
|
47 | + public $DividedHighwayAvoidPreference; |
|
48 | + public $FreewayAvoidPreference; |
|
49 | + public $InternationalBordersOpen; |
|
50 | + public $TollRoadUsage; |
|
51 | + public $hwy_only; |
|
52 | + public $long_combination_vehicle; |
|
53 | + public $avoid_highways; |
|
54 | + public $side_street_adherence; |
|
55 | + public $truck_config; |
|
56 | + public $height_metric; |
|
57 | + public $length_metric; |
|
58 | + public $width_metric; |
|
59 | + public $weight_metric; |
|
60 | + public $max_weight_per_axle_group_metric; |
|
61 | 61 | |
62 | - public function __construct () |
|
63 | - { |
|
64 | - Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
65 | - } |
|
62 | + public function __construct () |
|
63 | + { |
|
64 | + Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
65 | + } |
|
66 | 66 | |
67 | - public static function fromArray(array $params) { |
|
68 | - $vehicle= new Vehicle(); |
|
69 | - foreach($params as $key => $value) { |
|
70 | - if (property_exists($vehicle, $key)) { |
|
71 | - $vehicle->{$key} = $value; |
|
72 | - } |
|
73 | - } |
|
67 | + public static function fromArray(array $params) { |
|
68 | + $vehicle= new Vehicle(); |
|
69 | + foreach($params as $key => $value) { |
|
70 | + if (property_exists($vehicle, $key)) { |
|
71 | + $vehicle->{$key} = $value; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - return $vehicle; |
|
76 | - } |
|
75 | + return $vehicle; |
|
76 | + } |
|
77 | 77 | |
78 | - public static function getVehicles($params) |
|
79 | - { |
|
80 | - $allQueryFields = array('with_pagination', 'page', 'perPage'); |
|
78 | + public static function getVehicles($params) |
|
79 | + { |
|
80 | + $allQueryFields = array('with_pagination', 'page', 'perPage'); |
|
81 | 81 | |
82 | - $response = Route4Me::makeRequst(array( |
|
83 | - 'url' => Endpoint::VEHICLE_V4, |
|
84 | - 'method' => 'GET', |
|
85 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
86 | - )); |
|
82 | + $response = Route4Me::makeRequst(array( |
|
83 | + 'url' => Endpoint::VEHICLE_V4, |
|
84 | + 'method' => 'GET', |
|
85 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
86 | + )); |
|
87 | 87 | |
88 | - return $response; |
|
89 | - } |
|
88 | + return $response; |
|
89 | + } |
|
90 | 90 | |
91 | - public function getRandomVehicleId($page,$perPage) |
|
92 | - { |
|
93 | - $params = array( |
|
94 | - 'page' => isset($page) ? $page : 1, |
|
95 | - 'perPage' => isset($perPage) ? $perPage : 10, |
|
96 | - 'with_pagination' => true |
|
97 | - ); |
|
91 | + public function getRandomVehicleId($page,$perPage) |
|
92 | + { |
|
93 | + $params = array( |
|
94 | + 'page' => isset($page) ? $page : 1, |
|
95 | + 'perPage' => isset($perPage) ? $perPage : 10, |
|
96 | + 'with_pagination' => true |
|
97 | + ); |
|
98 | 98 | |
99 | - $vehicles = $this->getVehicles($params); |
|
99 | + $vehicles = $this->getVehicles($params); |
|
100 | 100 | |
101 | - if (is_null($vehicles)) return null; |
|
102 | - if (!isset($vehicles['data'])) return null; |
|
103 | - if (sizeof($vehicles['data'])<1) return null; |
|
101 | + if (is_null($vehicles)) return null; |
|
102 | + if (!isset($vehicles['data'])) return null; |
|
103 | + if (sizeof($vehicles['data'])<1) return null; |
|
104 | 104 | |
105 | - $randomIndex = rand(0, sizeof($vehicles['data'])-1); |
|
105 | + $randomIndex = rand(0, sizeof($vehicles['data'])-1); |
|
106 | 106 | |
107 | - return $vehicles['data'][$randomIndex]['vehicle_id']; |
|
108 | - } |
|
107 | + return $vehicles['data'][$randomIndex]['vehicle_id']; |
|
108 | + } |
|
109 | 109 | |
110 | - public function getVehicleByID($vehicleID) |
|
111 | - { |
|
112 | - $response = Route4Me::makeRequst(array( |
|
113 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
114 | - 'method' => 'GET' |
|
115 | - )); |
|
110 | + public function getVehicleByID($vehicleID) |
|
111 | + { |
|
112 | + $response = Route4Me::makeRequst(array( |
|
113 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
114 | + 'method' => 'GET' |
|
115 | + )); |
|
116 | 116 | |
117 | - return $response; |
|
118 | - } |
|
117 | + return $response; |
|
118 | + } |
|
119 | 119 | |
120 | - public function updateVehicle($params) |
|
121 | - { |
|
122 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
120 | + public function updateVehicle($params) |
|
121 | + { |
|
122 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
123 | 123 | |
124 | - $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
124 | + $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
125 | 125 | |
126 | - $response = Route4Me::makeRequst(array( |
|
127 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
128 | - 'method' => 'PUT', |
|
129 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
130 | - 'HTTPHEADER' => 'Content-Type: application/json' |
|
131 | - )); |
|
126 | + $response = Route4Me::makeRequst(array( |
|
127 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
128 | + 'method' => 'PUT', |
|
129 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
130 | + 'HTTPHEADER' => 'Content-Type: application/json' |
|
131 | + )); |
|
132 | 132 | |
133 | - return $response; |
|
134 | - } |
|
133 | + return $response; |
|
134 | + } |
|
135 | 135 | |
136 | - public function createVehicle($params) |
|
137 | - { |
|
138 | - $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
136 | + public function createVehicle($params) |
|
137 | + { |
|
138 | + $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
139 | 139 | |
140 | - $response = Route4Me::makeRequst(array( |
|
141 | - 'url' => Endpoint::VEHICLE_V4, |
|
142 | - 'method' => 'POST', |
|
143 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
144 | - 'HTTPHEADER' => 'Content-Type: application/json' |
|
145 | - )); |
|
140 | + $response = Route4Me::makeRequst(array( |
|
141 | + 'url' => Endpoint::VEHICLE_V4, |
|
142 | + 'method' => 'POST', |
|
143 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
144 | + 'HTTPHEADER' => 'Content-Type: application/json' |
|
145 | + )); |
|
146 | 146 | |
147 | - return $response; |
|
148 | - } |
|
147 | + return $response; |
|
148 | + } |
|
149 | 149 | |
150 | - public function removeVehicle($params) |
|
151 | - { |
|
152 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
150 | + public function removeVehicle($params) |
|
151 | + { |
|
152 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
153 | 153 | |
154 | - $response = Route4Me::makeRequst(array( |
|
155 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
156 | - 'method' => 'DELETE', |
|
157 | - 'HTTPHEADER' => 'Content-Type: application/json' |
|
158 | - )); |
|
154 | + $response = Route4Me::makeRequst(array( |
|
155 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
156 | + 'method' => 'DELETE', |
|
157 | + 'HTTPHEADER' => 'Content-Type: application/json' |
|
158 | + )); |
|
159 | 159 | |
160 | - return $response; |
|
161 | - } |
|
160 | + return $response; |
|
161 | + } |
|
162 | 162 | } |
@@ -7,415 +7,415 @@ |
||
7 | 7 | |
8 | 8 | class Route4Me |
9 | 9 | { |
10 | - static public $apiKey; |
|
11 | - static public $baseUrl = Endpoint::BASE_URL; |
|
10 | + static public $apiKey; |
|
11 | + static public $baseUrl = Endpoint::BASE_URL; |
|
12 | 12 | |
13 | - public static function setApiKey($apiKey) |
|
14 | - { |
|
15 | - self::$apiKey = $apiKey; |
|
16 | - } |
|
13 | + public static function setApiKey($apiKey) |
|
14 | + { |
|
15 | + self::$apiKey = $apiKey; |
|
16 | + } |
|
17 | 17 | |
18 | - public static function getApiKey() |
|
19 | - { |
|
20 | - return self::$apiKey; |
|
21 | - } |
|
18 | + public static function getApiKey() |
|
19 | + { |
|
20 | + return self::$apiKey; |
|
21 | + } |
|
22 | 22 | |
23 | - public static function setBaseUrl($baseUrl) |
|
24 | - { |
|
25 | - self::$baseUrl = $baseUrl; |
|
26 | - } |
|
23 | + public static function setBaseUrl($baseUrl) |
|
24 | + { |
|
25 | + self::$baseUrl = $baseUrl; |
|
26 | + } |
|
27 | 27 | |
28 | - public static function getBaseUrl() |
|
29 | - { |
|
30 | - return self::$baseUrl; |
|
31 | - } |
|
28 | + public static function getBaseUrl() |
|
29 | + { |
|
30 | + return self::$baseUrl; |
|
31 | + } |
|
32 | 32 | |
33 | - public static function fileUploadRequest($options) { |
|
34 | - $query = isset($options['query']) ? array_filter($options['query']) : array(); |
|
33 | + public static function fileUploadRequest($options) { |
|
34 | + $query = isset($options['query']) ? array_filter($options['query']) : array(); |
|
35 | 35 | |
36 | - if (sizeof($query)==0) { |
|
37 | - return null; |
|
36 | + if (sizeof($query)==0) { |
|
37 | + return null; |
|
38 | 38 | |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - $body = isset($options['body']) ? array_filter($options['body']) : null; |
|
41 | + $body = isset($options['body']) ? array_filter($options['body']) : null; |
|
42 | 42 | |
43 | - $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
|
43 | + $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
|
44 | 44 | |
45 | - if ($fname=='') { |
|
46 | - return null; |
|
47 | - } |
|
45 | + if ($fname=='') { |
|
46 | + return null; |
|
47 | + } |
|
48 | 48 | |
49 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fname)) : '@'.realpath($fname); |
|
49 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fname)) : '@'.realpath($fname); |
|
50 | 50 | |
51 | - $url = self::$baseUrl.$options['url'].'?'.http_build_query(array_merge(array('api_key' => self::getApiKey()), $query)); |
|
51 | + $url = self::$baseUrl.$options['url'].'?'.http_build_query(array_merge(array('api_key' => self::getApiKey()), $query)); |
|
52 | 52 | |
53 | - $ch = curl_init($url); |
|
53 | + $ch = curl_init($url); |
|
54 | 54 | |
55 | - $curlOpts = array( |
|
56 | - CURLOPT_POST => true, |
|
57 | - CURLOPT_RETURNTRANSFER => false, |
|
58 | - CURLOPT_TIMEOUT => 60, |
|
59 | - CURLOPT_FOLLOWLOCATION => true, |
|
60 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
61 | - CURLOPT_SSL_VERIFYPEER => FALSE |
|
62 | - ); |
|
55 | + $curlOpts = array( |
|
56 | + CURLOPT_POST => true, |
|
57 | + CURLOPT_RETURNTRANSFER => false, |
|
58 | + CURLOPT_TIMEOUT => 60, |
|
59 | + CURLOPT_FOLLOWLOCATION => true, |
|
60 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
61 | + CURLOPT_SSL_VERIFYPEER => FALSE |
|
62 | + ); |
|
63 | 63 | |
64 | - curl_setopt_array($ch, $curlOpts); |
|
64 | + curl_setopt_array($ch, $curlOpts); |
|
65 | 65 | |
66 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
66 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
67 | 67 | |
68 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
69 | - "Content-Type: multipart/form-data", |
|
70 | - 'Content-Disposition: form-data; name="strFilename"' |
|
71 | - )); |
|
72 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
73 | - curl_setopt($ch, CURLOPT_POSTFIELDS, array('strFilename' => $rpath)); |
|
68 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
69 | + "Content-Type: multipart/form-data", |
|
70 | + 'Content-Disposition: form-data; name="strFilename"' |
|
71 | + )); |
|
72 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
73 | + curl_setopt($ch, CURLOPT_POSTFIELDS, array('strFilename' => $rpath)); |
|
74 | 74 | |
75 | - $result = curl_exec($ch); |
|
75 | + $result = curl_exec($ch); |
|
76 | 76 | |
77 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
78 | - curl_close($ch); |
|
77 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
78 | + curl_close($ch); |
|
79 | 79 | |
80 | - $json = json_decode($result, true); |
|
80 | + $json = json_decode($result, true); |
|
81 | 81 | |
82 | - if (200==$code) { |
|
83 | - return $json; |
|
84 | - } elseif (isset($json['errors'])) { |
|
85 | - throw new ApiError(implode(', ', $json['errors'])); |
|
86 | - } else { |
|
87 | - throw new ApiError('Something wrong'); |
|
88 | - } |
|
89 | - } |
|
82 | + if (200==$code) { |
|
83 | + return $json; |
|
84 | + } elseif (isset($json['errors'])) { |
|
85 | + throw new ApiError(implode(', ', $json['errors'])); |
|
86 | + } else { |
|
87 | + throw new ApiError('Something wrong'); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - public static function makeRequst($options) { |
|
92 | - $errorHandler = new myErrorHandler(); |
|
91 | + public static function makeRequst($options) { |
|
92 | + $errorHandler = new myErrorHandler(); |
|
93 | 93 | |
94 | - $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
94 | + $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
95 | 95 | |
96 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
97 | - $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
96 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
97 | + $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
98 | 98 | |
99 | - $body = isset($options['body']) ? $options['body'] : null; |
|
100 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
101 | - $headers = array( |
|
102 | - "User-Agent: Route4Me php-sdk" |
|
103 | - ); |
|
99 | + $body = isset($options['body']) ? $options['body'] : null; |
|
100 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
101 | + $headers = array( |
|
102 | + "User-Agent: Route4Me php-sdk" |
|
103 | + ); |
|
104 | 104 | |
105 | - if (isset($options['HTTPHEADER'])) { |
|
106 | - $headers[] = $options['HTTPHEADER']; |
|
107 | - } |
|
105 | + if (isset($options['HTTPHEADER'])) { |
|
106 | + $headers[] = $options['HTTPHEADER']; |
|
107 | + } |
|
108 | 108 | |
109 | - if (isset($options['HTTPHEADERS'])) { |
|
110 | - foreach ($options['HTTPHEADERS'] As $header) { |
|
111 | - $headers[] = $header; |
|
112 | - } |
|
113 | - } |
|
109 | + if (isset($options['HTTPHEADERS'])) { |
|
110 | + foreach ($options['HTTPHEADERS'] As $header) { |
|
111 | + $headers[] = $header; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - $ch = curl_init(); |
|
115 | + $ch = curl_init(); |
|
116 | 116 | |
117 | - $url = $options['url'].'?'.http_build_query(array_merge( |
|
118 | - $query, array('api_key' => self::getApiKey()) |
|
119 | - )); |
|
117 | + $url = $options['url'].'?'.http_build_query(array_merge( |
|
118 | + $query, array('api_key' => self::getApiKey()) |
|
119 | + )); |
|
120 | 120 | |
121 | - $baseUrl = self::getBaseUrl(); |
|
121 | + $baseUrl = self::getBaseUrl(); |
|
122 | 122 | |
123 | - $curlOpts = arraY( |
|
124 | - CURLOPT_URL => $baseUrl.$url, |
|
125 | - CURLOPT_RETURNTRANSFER => true, |
|
126 | - CURLOPT_TIMEOUT => 80, |
|
127 | - CURLOPT_FOLLOWLOCATION => true, |
|
128 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
129 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
130 | - CURLOPT_HTTPHEADER => $headers |
|
131 | - ); |
|
123 | + $curlOpts = arraY( |
|
124 | + CURLOPT_URL => $baseUrl.$url, |
|
125 | + CURLOPT_RETURNTRANSFER => true, |
|
126 | + CURLOPT_TIMEOUT => 80, |
|
127 | + CURLOPT_FOLLOWLOCATION => true, |
|
128 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
129 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
130 | + CURLOPT_HTTPHEADER => $headers |
|
131 | + ); |
|
132 | 132 | |
133 | - curl_setopt_array($ch, $curlOpts); |
|
133 | + curl_setopt_array($ch, $curlOpts); |
|
134 | 134 | |
135 | - if ($file!=null) { |
|
136 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
137 | - $fp=fopen($file, 'r'); |
|
138 | - curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
139 | - curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
140 | - } |
|
135 | + if ($file!=null) { |
|
136 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
137 | + $fp=fopen($file, 'r'); |
|
138 | + curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
139 | + curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
140 | + } |
|
141 | 141 | |
142 | - switch ($method) { |
|
143 | - case 'DELETE': |
|
144 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
145 | - break; |
|
146 | - case 'DELETEARRAY': |
|
147 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
148 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
149 | - break; |
|
150 | - case 'PUT': |
|
151 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
152 | - break; |
|
153 | - case 'POST': |
|
154 | - if (isset($body)) { |
|
155 | - $bodyData = json_encode($body); |
|
156 | - if (isset($options['HTTPHEADER'])) { |
|
157 | - if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
158 | - $bodyData = $body; |
|
159 | - } |
|
160 | - } |
|
142 | + switch ($method) { |
|
143 | + case 'DELETE': |
|
144 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
145 | + break; |
|
146 | + case 'DELETEARRAY': |
|
147 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
148 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
149 | + break; |
|
150 | + case 'PUT': |
|
151 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
152 | + break; |
|
153 | + case 'POST': |
|
154 | + if (isset($body)) { |
|
155 | + $bodyData = json_encode($body); |
|
156 | + if (isset($options['HTTPHEADER'])) { |
|
157 | + if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
158 | + $bodyData = $body; |
|
159 | + } |
|
160 | + } |
|
161 | 161 | |
162 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
163 | - } |
|
164 | - break; |
|
165 | - case 'ADD': |
|
166 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
167 | - } |
|
162 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
163 | + } |
|
164 | + break; |
|
165 | + case 'ADD': |
|
166 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
167 | + } |
|
168 | 168 | |
169 | - if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
170 | - if (isset($body)) { |
|
171 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
172 | - } |
|
173 | - } |
|
169 | + if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
170 | + if (isset($body)) { |
|
171 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - $result = curl_exec($ch); |
|
175 | + $result = curl_exec($ch); |
|
176 | 176 | |
177 | - $isxml = FALSE; |
|
178 | - $jxml = ""; |
|
179 | - if (strpos($result, '<?xml')>-1) { |
|
180 | - $xml = simplexml_load_string($result); |
|
181 | - //$jxml = json_encode($xml); |
|
182 | - $jxml = self::object2array($xml); |
|
183 | - $isxml = TRUE; |
|
184 | - } |
|
177 | + $isxml = FALSE; |
|
178 | + $jxml = ""; |
|
179 | + if (strpos($result, '<?xml')>-1) { |
|
180 | + $xml = simplexml_load_string($result); |
|
181 | + //$jxml = json_encode($xml); |
|
182 | + $jxml = self::object2array($xml); |
|
183 | + $isxml = TRUE; |
|
184 | + } |
|
185 | 185 | |
186 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
187 | - curl_close($ch); |
|
186 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
187 | + curl_close($ch); |
|
188 | 188 | |
189 | - if (200==$code) { |
|
190 | - if ($isxml) { |
|
191 | - $json = $jxml; |
|
192 | - } else { |
|
193 | - $json = json_decode($result, true); |
|
194 | - } |
|
189 | + if (200==$code) { |
|
190 | + if ($isxml) { |
|
191 | + $json = $jxml; |
|
192 | + } else { |
|
193 | + $json = json_decode($result, true); |
|
194 | + } |
|
195 | 195 | |
196 | - if (isset($json['errors'])) { |
|
197 | - throw new ApiError(implode(', ', $json['errors'])); |
|
198 | - } else { |
|
199 | - return $json; |
|
200 | - } |
|
201 | - } elseif (409==$code) { |
|
202 | - throw new ApiError('Wrong API key'); |
|
203 | - } else { |
|
204 | - throw new ApiError('Something wrong'); |
|
205 | - } |
|
206 | - } |
|
196 | + if (isset($json['errors'])) { |
|
197 | + throw new ApiError(implode(', ', $json['errors'])); |
|
198 | + } else { |
|
199 | + return $json; |
|
200 | + } |
|
201 | + } elseif (409==$code) { |
|
202 | + throw new ApiError('Wrong API key'); |
|
203 | + } else { |
|
204 | + throw new ApiError('Something wrong'); |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @param $object: JSON object |
|
210 | - */ |
|
211 | - public static function object2array($object) |
|
212 | - { |
|
213 | - return @json_decode(@json_encode($object), 1); |
|
214 | - } |
|
208 | + /** |
|
209 | + * @param $object: JSON object |
|
210 | + */ |
|
211 | + public static function object2array($object) |
|
212 | + { |
|
213 | + return @json_decode(@json_encode($object), 1); |
|
214 | + } |
|
215 | 215 | |
216 | - public static function makeUrlRequst($url, $options) { |
|
217 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
218 | - $query = isset($options['query']) ? |
|
219 | - array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
220 | - $body = isset($options['body']) ? $options['body'] : null; |
|
221 | - $ch = curl_init(); |
|
216 | + public static function makeUrlRequst($url, $options) { |
|
217 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
218 | + $query = isset($options['query']) ? |
|
219 | + array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
220 | + $body = isset($options['body']) ? $options['body'] : null; |
|
221 | + $ch = curl_init(); |
|
222 | 222 | |
223 | - $curlOpts = arraY( |
|
224 | - CURLOPT_URL => $url, |
|
225 | - CURLOPT_RETURNTRANSFER => true, |
|
226 | - CURLOPT_TIMEOUT => 60, |
|
227 | - CURLOPT_FOLLOWLOCATION => true, |
|
228 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
229 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
230 | - CURLOPT_HTTPHEADER => array( |
|
231 | - 'User-Agent' => 'Route4Me php-sdk' |
|
232 | - ) |
|
233 | - ); |
|
223 | + $curlOpts = arraY( |
|
224 | + CURLOPT_URL => $url, |
|
225 | + CURLOPT_RETURNTRANSFER => true, |
|
226 | + CURLOPT_TIMEOUT => 60, |
|
227 | + CURLOPT_FOLLOWLOCATION => true, |
|
228 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
229 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
230 | + CURLOPT_HTTPHEADER => array( |
|
231 | + 'User-Agent' => 'Route4Me php-sdk' |
|
232 | + ) |
|
233 | + ); |
|
234 | 234 | |
235 | - curl_setopt_array($ch, $curlOpts); |
|
235 | + curl_setopt_array($ch, $curlOpts); |
|
236 | 236 | |
237 | - switch ($method) { |
|
238 | - case 'DELETE': |
|
239 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
240 | - break; |
|
241 | - case 'DELETEARRAY': |
|
242 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
243 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
244 | - break; |
|
245 | - case 'PUT': |
|
246 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
247 | - break; |
|
248 | - case 'POST': |
|
249 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
250 | - break; |
|
251 | - case 'ADD': |
|
252 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
253 | - } |
|
237 | + switch ($method) { |
|
238 | + case 'DELETE': |
|
239 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
240 | + break; |
|
241 | + case 'DELETEARRAY': |
|
242 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
243 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
244 | + break; |
|
245 | + case 'PUT': |
|
246 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
247 | + break; |
|
248 | + case 'POST': |
|
249 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
250 | + break; |
|
251 | + case 'ADD': |
|
252 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
253 | + } |
|
254 | 254 | |
255 | - if (is_numeric(array_search($method, array('DELETE', 'PUT', 'POST')))) { |
|
256 | - if (isset($body)) { |
|
257 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
258 | - } |
|
259 | - } |
|
255 | + if (is_numeric(array_search($method, array('DELETE', 'PUT', 'POST')))) { |
|
256 | + if (isset($body)) { |
|
257 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | - $result = curl_exec($ch); |
|
261 | + $result = curl_exec($ch); |
|
262 | 262 | |
263 | - $isxml = FALSE; |
|
264 | - $jxml = ""; |
|
263 | + $isxml = FALSE; |
|
264 | + $jxml = ""; |
|
265 | 265 | |
266 | - if (strpos($result, '<?xml')>-1) { |
|
267 | - $xml = simplexml_load_string($result); |
|
268 | - $jxml = json_encode($xml); |
|
269 | - $isxml = TRUE; |
|
270 | - } |
|
266 | + if (strpos($result, '<?xml')>-1) { |
|
267 | + $xml = simplexml_load_string($result); |
|
268 | + $jxml = json_encode($xml); |
|
269 | + $isxml = TRUE; |
|
270 | + } |
|
271 | 271 | |
272 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
273 | - curl_close($ch); |
|
272 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
273 | + curl_close($ch); |
|
274 | 274 | |
275 | - if ($isxml) { |
|
276 | - $json = $jxml; |
|
277 | - } else { |
|
278 | - $json = json_decode($result, true); |
|
279 | - } |
|
275 | + if ($isxml) { |
|
276 | + $json = $jxml; |
|
277 | + } else { |
|
278 | + $json = json_decode($result, true); |
|
279 | + } |
|
280 | 280 | |
281 | - if (200==$code) { |
|
282 | - return $json; |
|
283 | - } elseif (isset($json['errors'])) { |
|
284 | - throw new ApiError(implode(', ', $json['errors'])); |
|
285 | - } else { |
|
286 | - throw new ApiError('Something wrong'); |
|
287 | - } |
|
288 | - } |
|
281 | + if (200==$code) { |
|
282 | + return $json; |
|
283 | + } elseif (isset($json['errors'])) { |
|
284 | + throw new ApiError(implode(', ', $json['errors'])); |
|
285 | + } else { |
|
286 | + throw new ApiError('Something wrong'); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * Prints on the screen main keys and values of the array |
|
292 | - * @param $results: object to be printed on the screen. |
|
293 | - * @param $deepPrinting: if true, object will be printed recursively. |
|
294 | - */ |
|
295 | - public static function simplePrint($results, $deepPrinting = null) |
|
296 | - { |
|
297 | - if (isset($results)) { |
|
298 | - if (is_array($results)) { |
|
299 | - foreach ($results as $key=>$result) { |
|
300 | - if (is_array($result)) { |
|
301 | - foreach ($result as $key1=>$result1) { |
|
302 | - if (is_array($result1)) { |
|
303 | - if ($deepPrinting) { |
|
304 | - echo "<br>$key1 ------><br>"; |
|
305 | - Route4Me::simplePrint($result1, true); |
|
306 | - echo "------<br>"; |
|
307 | - } else { |
|
308 | - echo $key1." --> "."Array() <br>"; |
|
309 | - } |
|
310 | - } else { |
|
311 | - if (is_object($result1)) { |
|
312 | - if ($deepPrinting) { |
|
313 | - echo "<br>$key1 ------><br>"; |
|
314 | - $oarray = (array)$result1; |
|
315 | - Route4Me::simplePrint($oarray, true); |
|
316 | - echo "------<br>"; |
|
317 | - } else { |
|
318 | - echo $key1." --> "."Object <br>"; |
|
319 | - } |
|
320 | - } else { |
|
321 | - if (!is_null($result1)) { |
|
322 | - echo $key1." --> ".$result1."<br>"; |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - } |
|
327 | - } else { |
|
328 | - if (is_object($result)) { |
|
329 | - if ($deepPrinting) { |
|
330 | - echo "<br>$key ------><br>"; |
|
331 | - $oarray = (array)$result; |
|
332 | - Route4Me::simplePrint($oarray, true); |
|
333 | - echo "------<br>"; |
|
334 | - } else { |
|
335 | - echo $key." --> "."Object <br>"; |
|
336 | - } |
|
337 | - } else { |
|
338 | - if (!is_null($result)) { |
|
339 | - echo $key." --> ".$result."<br>"; |
|
340 | - } |
|
341 | - } |
|
290 | + /** |
|
291 | + * Prints on the screen main keys and values of the array |
|
292 | + * @param $results: object to be printed on the screen. |
|
293 | + * @param $deepPrinting: if true, object will be printed recursively. |
|
294 | + */ |
|
295 | + public static function simplePrint($results, $deepPrinting = null) |
|
296 | + { |
|
297 | + if (isset($results)) { |
|
298 | + if (is_array($results)) { |
|
299 | + foreach ($results as $key=>$result) { |
|
300 | + if (is_array($result)) { |
|
301 | + foreach ($result as $key1=>$result1) { |
|
302 | + if (is_array($result1)) { |
|
303 | + if ($deepPrinting) { |
|
304 | + echo "<br>$key1 ------><br>"; |
|
305 | + Route4Me::simplePrint($result1, true); |
|
306 | + echo "------<br>"; |
|
307 | + } else { |
|
308 | + echo $key1." --> "."Array() <br>"; |
|
309 | + } |
|
310 | + } else { |
|
311 | + if (is_object($result1)) { |
|
312 | + if ($deepPrinting) { |
|
313 | + echo "<br>$key1 ------><br>"; |
|
314 | + $oarray = (array)$result1; |
|
315 | + Route4Me::simplePrint($oarray, true); |
|
316 | + echo "------<br>"; |
|
317 | + } else { |
|
318 | + echo $key1." --> "."Object <br>"; |
|
319 | + } |
|
320 | + } else { |
|
321 | + if (!is_null($result1)) { |
|
322 | + echo $key1." --> ".$result1."<br>"; |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + } |
|
327 | + } else { |
|
328 | + if (is_object($result)) { |
|
329 | + if ($deepPrinting) { |
|
330 | + echo "<br>$key ------><br>"; |
|
331 | + $oarray = (array)$result; |
|
332 | + Route4Me::simplePrint($oarray, true); |
|
333 | + echo "------<br>"; |
|
334 | + } else { |
|
335 | + echo $key." --> "."Object <br>"; |
|
336 | + } |
|
337 | + } else { |
|
338 | + if (!is_null($result)) { |
|
339 | + echo $key." --> ".$result."<br>"; |
|
340 | + } |
|
341 | + } |
|
342 | 342 | |
343 | - } |
|
344 | - //echo "<br>"; |
|
345 | - } |
|
346 | - } |
|
347 | - } |
|
348 | - } |
|
343 | + } |
|
344 | + //echo "<br>"; |
|
345 | + } |
|
346 | + } |
|
347 | + } |
|
348 | + } |
|
349 | 349 | |
350 | - /** |
|
351 | - * Generates query or body parameters. |
|
352 | - * @param $allFields: all known fields could be used for parameters generation. |
|
353 | - * @param $params: input parameters (array or object) |
|
354 | - */ |
|
355 | - public static function generateRequestParameters($allFields, $params) |
|
356 | - { |
|
357 | - $generatedParams = array(); |
|
350 | + /** |
|
351 | + * Generates query or body parameters. |
|
352 | + * @param $allFields: all known fields could be used for parameters generation. |
|
353 | + * @param $params: input parameters (array or object) |
|
354 | + */ |
|
355 | + public static function generateRequestParameters($allFields, $params) |
|
356 | + { |
|
357 | + $generatedParams = array(); |
|
358 | 358 | |
359 | - if (is_array($params)) { |
|
360 | - foreach ($allFields as $field) { |
|
361 | - if (isset($params[$field])) { |
|
362 | - $generatedParams[$field] = $params[$field]; |
|
363 | - } |
|
364 | - } |
|
365 | - } elseif (is_object($params)) { |
|
366 | - foreach ($allFields as $field) { |
|
367 | - if (isset($params->{$field})) { |
|
368 | - $generatedParams[$field] = $params->{$field}; |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
359 | + if (is_array($params)) { |
|
360 | + foreach ($allFields as $field) { |
|
361 | + if (isset($params[$field])) { |
|
362 | + $generatedParams[$field] = $params[$field]; |
|
363 | + } |
|
364 | + } |
|
365 | + } elseif (is_object($params)) { |
|
366 | + foreach ($allFields as $field) { |
|
367 | + if (isset($params->{$field})) { |
|
368 | + $generatedParams[$field] = $params->{$field}; |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | 372 | |
373 | - return $generatedParams; |
|
374 | - } |
|
373 | + return $generatedParams; |
|
374 | + } |
|
375 | 375 | |
376 | - /** |
|
377 | - * Returns an array of the object properties |
|
378 | - * @param $object: An object. |
|
379 | - * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
380 | - */ |
|
381 | - public static function getObjectProperties($object, $exclude) |
|
382 | - { |
|
383 | - $objectParameters = array(); |
|
376 | + /** |
|
377 | + * Returns an array of the object properties |
|
378 | + * @param $object: An object. |
|
379 | + * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
380 | + */ |
|
381 | + public static function getObjectProperties($object, $exclude) |
|
382 | + { |
|
383 | + $objectParameters = array(); |
|
384 | 384 | |
385 | - foreach (get_object_vars($object) as $key => $value) { |
|
386 | - if (property_exists($object, $key)) { |
|
387 | - if (!is_numeric(array_search($key, $exclude))) { |
|
388 | - array_push($objectParameters, $key); |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
385 | + foreach (get_object_vars($object) as $key => $value) { |
|
386 | + if (property_exists($object, $key)) { |
|
387 | + if (!is_numeric(array_search($key, $exclude))) { |
|
388 | + array_push($objectParameters, $key); |
|
389 | + } |
|
390 | + } |
|
391 | + } |
|
392 | 392 | |
393 | - return $objectParameters; |
|
394 | - } |
|
393 | + return $objectParameters; |
|
394 | + } |
|
395 | 395 | |
396 | - /** |
|
397 | - * Returns url path generated from the array of the fields and parameters. |
|
398 | - * @param $allFields; array of the paossible fields (parameter names). |
|
399 | - * @param $params: input parameters (array or object). |
|
400 | - */ |
|
401 | - public static function generateUrlPath($allFields, $params) |
|
402 | - { |
|
403 | - $generatedPath = ""; |
|
396 | + /** |
|
397 | + * Returns url path generated from the array of the fields and parameters. |
|
398 | + * @param $allFields; array of the paossible fields (parameter names). |
|
399 | + * @param $params: input parameters (array or object). |
|
400 | + */ |
|
401 | + public static function generateUrlPath($allFields, $params) |
|
402 | + { |
|
403 | + $generatedPath = ""; |
|
404 | 404 | |
405 | - if (is_array($params)) { |
|
406 | - foreach ($allFields as $field) { |
|
407 | - if (isset($params[$field])) { |
|
408 | - $generatedPath .= $params[$field].'/'; |
|
409 | - } |
|
410 | - } |
|
411 | - } elseif (is_object($params)) { |
|
412 | - foreach ($allFields as $field) { |
|
413 | - if (isset($params->{$field})) { |
|
414 | - $generatedPath .= $params->{$field}.'/'; |
|
415 | - } |
|
416 | - } |
|
417 | - } |
|
405 | + if (is_array($params)) { |
|
406 | + foreach ($allFields as $field) { |
|
407 | + if (isset($params[$field])) { |
|
408 | + $generatedPath .= $params[$field].'/'; |
|
409 | + } |
|
410 | + } |
|
411 | + } elseif (is_object($params)) { |
|
412 | + foreach ($allFields as $field) { |
|
413 | + if (isset($params->{$field})) { |
|
414 | + $generatedPath .= $params->{$field}.'/'; |
|
415 | + } |
|
416 | + } |
|
417 | + } |
|
418 | 418 | |
419 | - return $generatedPath; |
|
420 | - } |
|
419 | + return $generatedPath; |
|
420 | + } |
|
421 | 421 | } |