@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | $addresses = array(); |
30 | 30 | |
31 | 31 | foreach ($json as $address) { |
32 | - $addresses[] = Address::fromArray($address); |
|
32 | + $addresses[] = Address::fromArray($address); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | $parameters = RouteParameters::fromArray(array( |
36 | - "algorithm_type" => AlgorithmType::TSP, |
|
37 | - "distance_unit" => DistanceUnit::MILES, |
|
38 | - "device_type" => DeviceType::WEB, |
|
39 | - "optimize" => OptimizationType::DISTANCE, |
|
40 | - "travel_mode" => TravelMode::DRIVING, |
|
41 | - "route_max_duration" => 86400, |
|
42 | - "vehicle_capacity" => 1, |
|
43 | - "vehicle_max_distance_mi" => 10000, |
|
44 | - "rt" => true, |
|
45 | - "optimized_callback_url" => "https://requestb.in/1o6cgge1" |
|
36 | + "algorithm_type" => AlgorithmType::TSP, |
|
37 | + "distance_unit" => DistanceUnit::MILES, |
|
38 | + "device_type" => DeviceType::WEB, |
|
39 | + "optimize" => OptimizationType::DISTANCE, |
|
40 | + "travel_mode" => TravelMode::DRIVING, |
|
41 | + "route_max_duration" => 86400, |
|
42 | + "vehicle_capacity" => 1, |
|
43 | + "vehicle_max_distance_mi" => 10000, |
|
44 | + "rt" => true, |
|
45 | + "optimized_callback_url" => "https://requestb.in/1o6cgge1" |
|
46 | 46 | )); |
47 | 47 | |
48 | 48 | $optimizationParams = new OptimizationProblemParams; |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | $problems = OptimizationProblem::optimize($optimizationParams); |
53 | 53 | |
54 | 54 | foreach ($problems as $problem) { |
55 | - if (is_array($problem) || is_object($problem)) { |
|
56 | - foreach ($problem as $key => $value) { |
|
57 | - if (!is_object($value)) { |
|
58 | - echo $key." --> ".$value."<br>"; |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
55 | + if (is_array($problem) || is_object($problem)) { |
|
56 | + foreach ($problem as $key => $value) { |
|
57 | + if (!is_object($value)) { |
|
58 | + echo $key." --> ".$value."<br>"; |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | 62 | } |
@@ -23,25 +23,25 @@ |
||
23 | 23 | |
24 | 24 | // Get a route with the path points |
25 | 25 | $params = array( |
26 | - "route_path_output" => "Points", |
|
27 | - "route_id" => $route_id |
|
26 | + "route_path_output" => "Points", |
|
27 | + "route_id" => $route_id |
|
28 | 28 | ); |
29 | 29 | |
30 | 30 | $routeResults = (array)$route->getRoutePoints($params); |
31 | 31 | |
32 | 32 | if (isset($routeResults['addresses'])) { |
33 | - foreach ($routeResults['addresses'] as $key => $address) { |
|
34 | - $araddress = (array)$address; |
|
33 | + foreach ($routeResults['addresses'] as $key => $address) { |
|
34 | + $araddress = (array)$address; |
|
35 | 35 | |
36 | - if (isset($araddress['route_destination_id'])) { |
|
37 | - echo "route_destination_id=".$araddress['route_destination_id']."<br>"; |
|
38 | - } |
|
36 | + if (isset($araddress['route_destination_id'])) { |
|
37 | + echo "route_destination_id=".$araddress['route_destination_id']."<br>"; |
|
38 | + } |
|
39 | 39 | |
40 | - if (isset($araddress['path_to_next'])) { |
|
41 | - echo "path_to_next:<br>"; |
|
42 | - Route4Me::simplePrint($araddress['path_to_next']); |
|
43 | - } |
|
40 | + if (isset($araddress['path_to_next'])) { |
|
41 | + echo "path_to_next:<br>"; |
|
42 | + Route4Me::simplePrint($araddress['path_to_next']); |
|
43 | + } |
|
44 | 44 | |
45 | - echo "<br>"; |
|
46 | - } |
|
45 | + echo "<br>"; |
|
46 | + } |
|
47 | 47 | } |
@@ -3,9 +3,9 @@ |
||
3 | 3 | |
4 | 4 | class myErrorHandler extends \Exception |
5 | 5 | { |
6 | - public function proc_error($errno, $errstr, $errfile, $errline) |
|
7 | - { |
|
8 | - echo "Error No: $errno, line: $errline --- ".$errstr."<br>"; |
|
6 | + public function proc_error($errno, $errstr, $errfile, $errline) |
|
7 | + { |
|
8 | + echo "Error No: $errno, line: $errline --- ".$errstr."<br>"; |
|
9 | 9 | |
10 | - } |
|
10 | + } |
|
11 | 11 | } |
@@ -7,287 +7,287 @@ |
||
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 makeRequst($options) { |
|
34 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
35 | - $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
33 | + public static function makeRequst($options) { |
|
34 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
35 | + $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
36 | 36 | |
37 | - $body = isset($options['body']) ? $options['body'] : null; |
|
38 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
39 | - $headers = array( |
|
40 | - "User-Agent: Route4Me php-sdk" |
|
41 | - ); |
|
37 | + $body = isset($options['body']) ? $options['body'] : null; |
|
38 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
39 | + $headers = array( |
|
40 | + "User-Agent: Route4Me php-sdk" |
|
41 | + ); |
|
42 | 42 | |
43 | - if (isset($options['HTTPHEADER'])) { |
|
44 | - $headers[] = $options['HTTPHEADER']; |
|
45 | - } |
|
43 | + if (isset($options['HTTPHEADER'])) { |
|
44 | + $headers[] = $options['HTTPHEADER']; |
|
45 | + } |
|
46 | 46 | |
47 | - if (isset($options['HTTPHEADERS'])) { |
|
48 | - foreach ($options['HTTPHEADERS'] As $header) { |
|
49 | - $headers[] = $header; |
|
50 | - } |
|
51 | - } |
|
47 | + if (isset($options['HTTPHEADERS'])) { |
|
48 | + foreach ($options['HTTPHEADERS'] As $header) { |
|
49 | + $headers[] = $header; |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - $ch = curl_init(); |
|
53 | + $ch = curl_init(); |
|
54 | 54 | |
55 | - $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
56 | - $query, array('api_key' => self::getApiKey()) |
|
57 | - )) : ""; |
|
55 | + $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
56 | + $query, array('api_key' => self::getApiKey()) |
|
57 | + )) : ""; |
|
58 | 58 | |
59 | - $baseUrl = self::getBaseUrl(); |
|
59 | + $baseUrl = self::getBaseUrl(); |
|
60 | 60 | |
61 | - $curlOpts = array( |
|
62 | - CURLOPT_URL => $baseUrl.$url, |
|
63 | - CURLOPT_RETURNTRANSFER => true, |
|
64 | - CURLOPT_TIMEOUT => 80, |
|
65 | - CURLOPT_FOLLOWLOCATION => true, |
|
66 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
67 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
68 | - CURLOPT_HTTPHEADER => $headers |
|
69 | - ); |
|
61 | + $curlOpts = array( |
|
62 | + CURLOPT_URL => $baseUrl.$url, |
|
63 | + CURLOPT_RETURNTRANSFER => true, |
|
64 | + CURLOPT_TIMEOUT => 80, |
|
65 | + CURLOPT_FOLLOWLOCATION => true, |
|
66 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
67 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
68 | + CURLOPT_HTTPHEADER => $headers |
|
69 | + ); |
|
70 | 70 | |
71 | - curl_setopt_array($ch, $curlOpts); |
|
71 | + curl_setopt_array($ch, $curlOpts); |
|
72 | 72 | |
73 | - if ($file!=null) { |
|
74 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
75 | - $fp = fopen($file, 'r'); |
|
76 | - curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
77 | - curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
78 | - } |
|
73 | + if ($file!=null) { |
|
74 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
75 | + $fp = fopen($file, 'r'); |
|
76 | + curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
77 | + curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
78 | + } |
|
79 | 79 | |
80 | - switch ($method) { |
|
81 | - case 'DELETE': |
|
82 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
83 | - break; |
|
84 | - case 'DELETEARRAY': |
|
85 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
86 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
87 | - break; |
|
88 | - case 'PUT': |
|
89 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
90 | - break; |
|
91 | - case 'POST': |
|
92 | - if (isset($body)) { |
|
93 | - $bodyData = json_encode($body); |
|
94 | - if (isset($options['HTTPHEADER'])) { |
|
95 | - if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
96 | - $bodyData = $body; |
|
97 | - } |
|
98 | - } |
|
80 | + switch ($method) { |
|
81 | + case 'DELETE': |
|
82 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
83 | + break; |
|
84 | + case 'DELETEARRAY': |
|
85 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
86 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
87 | + break; |
|
88 | + case 'PUT': |
|
89 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
90 | + break; |
|
91 | + case 'POST': |
|
92 | + if (isset($body)) { |
|
93 | + $bodyData = json_encode($body); |
|
94 | + if (isset($options['HTTPHEADER'])) { |
|
95 | + if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
96 | + $bodyData = $body; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
101 | - } |
|
102 | - break; |
|
103 | - case 'ADD': |
|
104 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
105 | - } |
|
100 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
101 | + } |
|
102 | + break; |
|
103 | + case 'ADD': |
|
104 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
105 | + } |
|
106 | 106 | |
107 | - if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
108 | - if (isset($body)) { |
|
109 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
110 | - } |
|
111 | - } |
|
107 | + if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
108 | + if (isset($body)) { |
|
109 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | - $result = curl_exec($ch); |
|
113 | + $result = curl_exec($ch); |
|
114 | 114 | |
115 | - $isxml = FALSE; |
|
116 | - $jxml = ""; |
|
117 | - if (strpos($result, '<?xml')>-1) { |
|
118 | - $xml = simplexml_load_string($result); |
|
119 | - //$jxml = json_encode($xml); |
|
120 | - $jxml = self::object2array($xml); |
|
121 | - $isxml = TRUE; |
|
122 | - } |
|
115 | + $isxml = FALSE; |
|
116 | + $jxml = ""; |
|
117 | + if (strpos($result, '<?xml')>-1) { |
|
118 | + $xml = simplexml_load_string($result); |
|
119 | + //$jxml = json_encode($xml); |
|
120 | + $jxml = self::object2array($xml); |
|
121 | + $isxml = TRUE; |
|
122 | + } |
|
123 | 123 | |
124 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
125 | - curl_close($ch); |
|
124 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
125 | + curl_close($ch); |
|
126 | 126 | |
127 | - if (200==$code) { |
|
128 | - if ($isxml) { |
|
129 | - $json = $jxml; |
|
130 | - } else { |
|
131 | - $json = json_decode($result, true); |
|
132 | - } |
|
127 | + if (200==$code) { |
|
128 | + if ($isxml) { |
|
129 | + $json = $jxml; |
|
130 | + } else { |
|
131 | + $json = json_decode($result, true); |
|
132 | + } |
|
133 | 133 | |
134 | - if (isset($json['errors'])) { |
|
135 | - throw new ApiError(implode(', ', $json['errors'])); |
|
136 | - } else { |
|
137 | - return $json; |
|
138 | - } |
|
139 | - } elseif (409==$code) { |
|
140 | - throw new ApiError('Wrong API key'); |
|
141 | - } else { |
|
142 | - throw new ApiError('Something wrong'); |
|
143 | - } |
|
144 | - } |
|
134 | + if (isset($json['errors'])) { |
|
135 | + throw new ApiError(implode(', ', $json['errors'])); |
|
136 | + } else { |
|
137 | + return $json; |
|
138 | + } |
|
139 | + } elseif (409==$code) { |
|
140 | + throw new ApiError('Wrong API key'); |
|
141 | + } else { |
|
142 | + throw new ApiError('Something wrong'); |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @param $object: JSON object |
|
148 | - */ |
|
149 | - public static function object2array($object) |
|
150 | - { |
|
151 | - return @json_decode(@json_encode($object), 1); |
|
152 | - } |
|
146 | + /** |
|
147 | + * @param $object: JSON object |
|
148 | + */ |
|
149 | + public static function object2array($object) |
|
150 | + { |
|
151 | + return @json_decode(@json_encode($object), 1); |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * Prints on the screen main keys and values of the array |
|
157 | - * @param $results: object to be printed on the screen. |
|
158 | - * @param $deepPrinting: if true, object will be printed recursively. |
|
159 | - */ |
|
160 | - public static function simplePrint($results, $deepPrinting = null) |
|
161 | - { |
|
162 | - if (isset($results)) { |
|
163 | - if (is_array($results)) { |
|
164 | - foreach ($results as $key=>$result) { |
|
165 | - if (is_array($result)) { |
|
166 | - foreach ($result as $key1=>$result1) { |
|
167 | - if (is_array($result1)) { |
|
168 | - if ($deepPrinting) { |
|
169 | - echo "<br>$key1 ------><br>"; |
|
170 | - Route4Me::simplePrint($result1, true); |
|
171 | - echo "------<br>"; |
|
172 | - } else { |
|
173 | - echo $key1." --> "."Array() <br>"; |
|
174 | - } |
|
175 | - } else { |
|
176 | - if (is_object($result1)) { |
|
177 | - if ($deepPrinting) { |
|
178 | - echo "<br>$key1 ------><br>"; |
|
179 | - $oarray = (array)$result1; |
|
180 | - Route4Me::simplePrint($oarray, true); |
|
181 | - echo "------<br>"; |
|
182 | - } else { |
|
183 | - echo $key1." --> "."Object <br>"; |
|
184 | - } |
|
185 | - } else { |
|
186 | - if (!is_null($result1)) { |
|
187 | - echo $key1." --> ".$result1."<br>"; |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
192 | - } else { |
|
193 | - if (is_object($result)) { |
|
194 | - if ($deepPrinting) { |
|
195 | - echo "<br>$key ------><br>"; |
|
196 | - $oarray = (array)$result; |
|
197 | - Route4Me::simplePrint($oarray, true); |
|
198 | - echo "------<br>"; |
|
199 | - } else { |
|
200 | - echo $key." --> "."Object <br>"; |
|
201 | - } |
|
202 | - } else { |
|
203 | - if (!is_null($result)) { |
|
204 | - echo $key." --> ".$result."<br>"; |
|
205 | - } |
|
206 | - } |
|
155 | + /** |
|
156 | + * Prints on the screen main keys and values of the array |
|
157 | + * @param $results: object to be printed on the screen. |
|
158 | + * @param $deepPrinting: if true, object will be printed recursively. |
|
159 | + */ |
|
160 | + public static function simplePrint($results, $deepPrinting = null) |
|
161 | + { |
|
162 | + if (isset($results)) { |
|
163 | + if (is_array($results)) { |
|
164 | + foreach ($results as $key=>$result) { |
|
165 | + if (is_array($result)) { |
|
166 | + foreach ($result as $key1=>$result1) { |
|
167 | + if (is_array($result1)) { |
|
168 | + if ($deepPrinting) { |
|
169 | + echo "<br>$key1 ------><br>"; |
|
170 | + Route4Me::simplePrint($result1, true); |
|
171 | + echo "------<br>"; |
|
172 | + } else { |
|
173 | + echo $key1." --> "."Array() <br>"; |
|
174 | + } |
|
175 | + } else { |
|
176 | + if (is_object($result1)) { |
|
177 | + if ($deepPrinting) { |
|
178 | + echo "<br>$key1 ------><br>"; |
|
179 | + $oarray = (array)$result1; |
|
180 | + Route4Me::simplePrint($oarray, true); |
|
181 | + echo "------<br>"; |
|
182 | + } else { |
|
183 | + echo $key1." --> "."Object <br>"; |
|
184 | + } |
|
185 | + } else { |
|
186 | + if (!is_null($result1)) { |
|
187 | + echo $key1." --> ".$result1."<br>"; |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | + } else { |
|
193 | + if (is_object($result)) { |
|
194 | + if ($deepPrinting) { |
|
195 | + echo "<br>$key ------><br>"; |
|
196 | + $oarray = (array)$result; |
|
197 | + Route4Me::simplePrint($oarray, true); |
|
198 | + echo "------<br>"; |
|
199 | + } else { |
|
200 | + echo $key." --> "."Object <br>"; |
|
201 | + } |
|
202 | + } else { |
|
203 | + if (!is_null($result)) { |
|
204 | + echo $key." --> ".$result."<br>"; |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - } |
|
209 | - //echo "<br>"; |
|
210 | - } |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
208 | + } |
|
209 | + //echo "<br>"; |
|
210 | + } |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Generates query or body parameters. |
|
217 | - * @param $allFields: all known fields could be used for parameters generation. |
|
218 | - * @param $params: input parameters (array or object) |
|
219 | - */ |
|
220 | - public static function generateRequestParameters($allFields, $params) |
|
221 | - { |
|
222 | - $generatedParams = array(); |
|
215 | + /** |
|
216 | + * Generates query or body parameters. |
|
217 | + * @param $allFields: all known fields could be used for parameters generation. |
|
218 | + * @param $params: input parameters (array or object) |
|
219 | + */ |
|
220 | + public static function generateRequestParameters($allFields, $params) |
|
221 | + { |
|
222 | + $generatedParams = array(); |
|
223 | 223 | |
224 | - if (is_array($params)) { |
|
225 | - foreach ($allFields as $field) { |
|
226 | - if (isset($params[$field])) { |
|
227 | - $generatedParams[$field] = $params[$field]; |
|
228 | - } |
|
229 | - } |
|
230 | - } elseif (is_object($params)) { |
|
231 | - foreach ($allFields as $field) { |
|
232 | - if (isset($params->{$field})) { |
|
233 | - $generatedParams[$field] = $params->{$field}; |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
224 | + if (is_array($params)) { |
|
225 | + foreach ($allFields as $field) { |
|
226 | + if (isset($params[$field])) { |
|
227 | + $generatedParams[$field] = $params[$field]; |
|
228 | + } |
|
229 | + } |
|
230 | + } elseif (is_object($params)) { |
|
231 | + foreach ($allFields as $field) { |
|
232 | + if (isset($params->{$field})) { |
|
233 | + $generatedParams[$field] = $params->{$field}; |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | 237 | |
238 | - return $generatedParams; |
|
239 | - } |
|
238 | + return $generatedParams; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Returns an array of the object properties |
|
243 | - * @param $object: An object. |
|
244 | - * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
245 | - */ |
|
246 | - public static function getObjectProperties($object, $exclude) |
|
247 | - { |
|
248 | - $objectParameters = array(); |
|
241 | + /** |
|
242 | + * Returns an array of the object properties |
|
243 | + * @param $object: An object. |
|
244 | + * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
245 | + */ |
|
246 | + public static function getObjectProperties($object, $exclude) |
|
247 | + { |
|
248 | + $objectParameters = array(); |
|
249 | 249 | |
250 | - foreach (get_object_vars($object) as $key => $value) { |
|
251 | - if (property_exists($object, $key)) { |
|
252 | - if (!is_numeric(array_search($key, $exclude))) { |
|
253 | - array_push($objectParameters, $key); |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
250 | + foreach (get_object_vars($object) as $key => $value) { |
|
251 | + if (property_exists($object, $key)) { |
|
252 | + if (!is_numeric(array_search($key, $exclude))) { |
|
253 | + array_push($objectParameters, $key); |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | 257 | |
258 | - return $objectParameters; |
|
259 | - } |
|
258 | + return $objectParameters; |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * Returns url path generated from the array of the fields and parameters. |
|
263 | - * @param $allFields; array of the paossible fields (parameter names). |
|
264 | - * @param $params: input parameters (array or object). |
|
265 | - */ |
|
266 | - public static function generateUrlPath($allFields, $params) |
|
267 | - { |
|
268 | - $generatedPath = ""; |
|
261 | + /** |
|
262 | + * Returns url path generated from the array of the fields and parameters. |
|
263 | + * @param $allFields; array of the paossible fields (parameter names). |
|
264 | + * @param $params: input parameters (array or object). |
|
265 | + */ |
|
266 | + public static function generateUrlPath($allFields, $params) |
|
267 | + { |
|
268 | + $generatedPath = ""; |
|
269 | 269 | |
270 | - if (is_array($params)) { |
|
271 | - foreach ($allFields as $field) { |
|
272 | - if (isset($params[$field])) { |
|
273 | - $generatedPath .= $params[$field].'/'; |
|
274 | - } |
|
275 | - } |
|
276 | - } elseif (is_object($params)) { |
|
277 | - foreach ($allFields as $field) { |
|
278 | - if (isset($params->{$field})) { |
|
279 | - $generatedPath .= $params->{$field}.'/'; |
|
280 | - } |
|
281 | - } |
|
282 | - } |
|
270 | + if (is_array($params)) { |
|
271 | + foreach ($allFields as $field) { |
|
272 | + if (isset($params[$field])) { |
|
273 | + $generatedPath .= $params[$field].'/'; |
|
274 | + } |
|
275 | + } |
|
276 | + } elseif (is_object($params)) { |
|
277 | + foreach ($allFields as $field) { |
|
278 | + if (isset($params->{$field})) { |
|
279 | + $generatedPath .= $params->{$field}.'/'; |
|
280 | + } |
|
281 | + } |
|
282 | + } |
|
283 | 283 | |
284 | - return $generatedPath; |
|
285 | - } |
|
284 | + return $generatedPath; |
|
285 | + } |
|
286 | 286 | |
287 | - public static function getFileRealPath($fileName) |
|
288 | - { |
|
289 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
287 | + public static function getFileRealPath($fileName) |
|
288 | + { |
|
289 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
290 | 290 | |
291 | - return $rpath; |
|
292 | - } |
|
291 | + return $rpath; |
|
292 | + } |
|
293 | 293 | } |
@@ -23,26 +23,26 @@ |
||
23 | 23 | |
24 | 24 | // Itereate through all the existing activity types |
25 | 25 | foreach ($activityTypes->getConstants() as $prop => $value) { |
26 | - $activityParameters = ActivityParameters::fromArray(array( |
|
27 | - "activity_type" => $value, |
|
28 | - "limit" => 2, |
|
29 | - "offset" => 0, |
|
30 | - "route_id" => $route_id |
|
31 | - )); |
|
26 | + $activityParameters = ActivityParameters::fromArray(array( |
|
27 | + "activity_type" => $value, |
|
28 | + "limit" => 2, |
|
29 | + "offset" => 0, |
|
30 | + "route_id" => $route_id |
|
31 | + )); |
|
32 | 32 | |
33 | - $activities = new ActivityParameters(); |
|
34 | - $results = $activities->searcActivities($activityParameters); |
|
33 | + $activities = new ActivityParameters(); |
|
34 | + $results = $activities->searcActivities($activityParameters); |
|
35 | 35 | |
36 | - if (!is_array($results) || !is_array($results['results']) || sizeof($results['results'])<1) { |
|
37 | - continue; |
|
38 | - } |
|
36 | + if (!is_array($results) || !is_array($results['results']) || sizeof($results['results'])<1) { |
|
37 | + continue; |
|
38 | + } |
|
39 | 39 | |
40 | - $count++; |
|
40 | + $count++; |
|
41 | 41 | |
42 | - foreach ($results as $key => $activity) { |
|
43 | - Route4Me::simplePrint($activity); |
|
44 | - echo "<br>"; |
|
45 | - } |
|
42 | + foreach ($results as $key => $activity) { |
|
43 | + Route4Me::simplePrint($activity); |
|
44 | + echo "<br>"; |
|
45 | + } |
|
46 | 46 | |
47 | - echo "------------------- <br><br>"; |
|
47 | + echo "------------------- <br><br>"; |
|
48 | 48 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | $route = new Route(); |
20 | 20 | $route_id = $route->getRandomRouteId(0, 10); |
21 | 21 | echo "route_id -> $route_id <br>"; |
22 | -$count=0; |
|
22 | +$count = 0; |
|
23 | 23 | |
24 | 24 | // Itereate through all the existing activity types |
25 | 25 | foreach ($activityTypes->getConstants() as $prop => $value) { |