@@ -12,221 +12,221 @@ |
||
12 | 12 | |
13 | 13 | class Ongkir extends Api |
14 | 14 | { |
15 | - private static $arr; |
|
16 | - private static $return; |
|
17 | - private static $province; |
|
18 | - private static $city; |
|
19 | - private static $cacheType; |
|
20 | - |
|
21 | - public static function find($arr) |
|
22 | - { |
|
23 | - if (is_array($arr)) { |
|
24 | - self::$arr = $arr; |
|
25 | - |
|
26 | - return new static(); |
|
27 | - } else { |
|
28 | - throw new Exception('Parameter must be an array.'); |
|
29 | - |
|
30 | - return false; |
|
31 | - } |
|
32 | - } |
|
33 | - |
|
34 | - public static function get() |
|
35 | - { |
|
36 | - self::$arr = null; //Clear parameter |
|
37 | - if (empty(self::$return)) { |
|
38 | - throw new Exception('Data is not defined.'); |
|
39 | - |
|
40 | - return false; |
|
41 | - } |
|
42 | - $ret = self::$return; |
|
43 | - self::$return = null; |
|
44 | - |
|
45 | - return $ret; |
|
46 | - } |
|
47 | - |
|
48 | - public static function cachingProvince() |
|
49 | - { |
|
50 | - self::cacheProvince(); |
|
51 | - } |
|
52 | - |
|
53 | - public static function cachingSubDistrict() |
|
54 | - { |
|
55 | - if(strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
56 | - { |
|
57 | - echo "Tidak dapat mengambil SubDistrict dikarenakan akun yg anda pakai tipe starter."; |
|
58 | - return true; |
|
59 | - } |
|
60 | - $get = self::cityData(); |
|
61 | - $count = count($get); |
|
62 | - $i=0; |
|
63 | - echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m"; |
|
64 | - foreach($get as $city){ |
|
65 | - $i++; |
|
66 | - echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m"; |
|
67 | - echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL; |
|
68 | - self::cacheSubDistrict(['city' => $city->city_id]); |
|
69 | - echo PHP_EOL; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - public static function cachingCity() |
|
74 | - { |
|
75 | - self::cacheCity(); |
|
76 | - } |
|
77 | - |
|
78 | - public static function costDetails() |
|
79 | - { |
|
80 | - self::$return = self::get_cost_details(self::$arr); |
|
81 | - |
|
82 | - return new static(); |
|
83 | - } |
|
84 | - public static function testConnection() |
|
85 | - { |
|
86 | - self::$return = self::test_connection(self::$arr); |
|
87 | - |
|
88 | - return new static(); |
|
89 | - } |
|
90 | - |
|
91 | - public static function courier() |
|
92 | - { |
|
93 | - self::$return = self::get_courier(self::$arr); |
|
94 | - |
|
95 | - return new static(); |
|
96 | - } |
|
15 | + private static $arr; |
|
16 | + private static $return; |
|
17 | + private static $province; |
|
18 | + private static $city; |
|
19 | + private static $cacheType; |
|
20 | + |
|
21 | + public static function find($arr) |
|
22 | + { |
|
23 | + if (is_array($arr)) { |
|
24 | + self::$arr = $arr; |
|
25 | + |
|
26 | + return new static(); |
|
27 | + } else { |
|
28 | + throw new Exception('Parameter must be an array.'); |
|
29 | + |
|
30 | + return false; |
|
31 | + } |
|
32 | + } |
|
33 | + |
|
34 | + public static function get() |
|
35 | + { |
|
36 | + self::$arr = null; //Clear parameter |
|
37 | + if (empty(self::$return)) { |
|
38 | + throw new Exception('Data is not defined.'); |
|
39 | + |
|
40 | + return false; |
|
41 | + } |
|
42 | + $ret = self::$return; |
|
43 | + self::$return = null; |
|
44 | + |
|
45 | + return $ret; |
|
46 | + } |
|
47 | + |
|
48 | + public static function cachingProvince() |
|
49 | + { |
|
50 | + self::cacheProvince(); |
|
51 | + } |
|
52 | + |
|
53 | + public static function cachingSubDistrict() |
|
54 | + { |
|
55 | + if(strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
56 | + { |
|
57 | + echo "Tidak dapat mengambil SubDistrict dikarenakan akun yg anda pakai tipe starter."; |
|
58 | + return true; |
|
59 | + } |
|
60 | + $get = self::cityData(); |
|
61 | + $count = count($get); |
|
62 | + $i=0; |
|
63 | + echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m"; |
|
64 | + foreach($get as $city){ |
|
65 | + $i++; |
|
66 | + echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m"; |
|
67 | + echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL; |
|
68 | + self::cacheSubDistrict(['city' => $city->city_id]); |
|
69 | + echo PHP_EOL; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + public static function cachingCity() |
|
74 | + { |
|
75 | + self::cacheCity(); |
|
76 | + } |
|
77 | + |
|
78 | + public static function costDetails() |
|
79 | + { |
|
80 | + self::$return = self::get_cost_details(self::$arr); |
|
81 | + |
|
82 | + return new static(); |
|
83 | + } |
|
84 | + public static function testConnection() |
|
85 | + { |
|
86 | + self::$return = self::test_connection(self::$arr); |
|
87 | + |
|
88 | + return new static(); |
|
89 | + } |
|
90 | + |
|
91 | + public static function courier() |
|
92 | + { |
|
93 | + self::$return = self::get_courier(self::$arr); |
|
94 | + |
|
95 | + return new static(); |
|
96 | + } |
|
97 | 97 | |
98 | - public static function province() |
|
99 | - { |
|
100 | - $ret = self::provinceData(); |
|
101 | - self::$return = $ret; |
|
102 | - |
|
103 | - return new static(); |
|
104 | - } |
|
105 | - |
|
106 | - public static function subDistrict() |
|
107 | - { |
|
108 | - $ret = self::subDistrictData(); |
|
109 | - self::$return = $ret; |
|
110 | - |
|
111 | - return new static(); |
|
112 | - } |
|
113 | - public static function internationalOrigin() |
|
114 | - { |
|
115 | - $ret = self::internationalOriginData(); |
|
116 | - self::$return = $ret; |
|
117 | - |
|
118 | - return new static(); |
|
119 | - } |
|
120 | - |
|
121 | - public static function city() |
|
122 | - { |
|
123 | - $ret = self::cityData(); |
|
124 | - self::$return = $ret; |
|
125 | - |
|
126 | - return new static(); |
|
127 | - } |
|
128 | - |
|
129 | - private static function setupConfig() |
|
130 | - { |
|
131 | - self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type')); |
|
132 | - self::$province = config('irfa.rajaongkir.province_table'); |
|
133 | - self::$city = config('irfa.rajaongkir.city_table'); |
|
134 | - } |
|
135 | - |
|
136 | - private static function provinceData() |
|
137 | - { |
|
138 | - if (function_exists('config') && function_exists('app')) { |
|
139 | - self::setupConfig(); |
|
140 | - $cache_type = self::$cacheType; |
|
141 | - if ($cache_type == 'database') { |
|
142 | - if (ROCache::checkProv()) { |
|
143 | - if (count(ROCache::getProv(self::$arr)) > 0) { |
|
144 | - $ret = ROCache::getProv(self::$arr); |
|
145 | - } else { |
|
146 | - $ret = self::get_province(self::$arr); |
|
147 | - } |
|
148 | - } |
|
149 | - } elseif ($cache_type == 'file') { |
|
150 | - $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
151 | - if ($ret == null) { |
|
152 | - self::exceptionCache(); |
|
153 | - } |
|
154 | - } else { |
|
155 | - $ret = self::get_province(self::$arr); |
|
156 | - } |
|
157 | - } else { |
|
158 | - $ret = self::get_province(self::$arr); |
|
159 | - } |
|
160 | - |
|
161 | - return $ret; |
|
162 | - } |
|
163 | - private static function subDistrictData() |
|
164 | - { |
|
165 | - if (function_exists('config') && function_exists('app')) { |
|
166 | - self::setupConfig(); |
|
167 | - $cache_type = self::$cacheType; |
|
168 | - if ($cache_type == 'database') { |
|
169 | - if (ROCache::checkProv()) { |
|
170 | - if (count(ROCache::getSubdistrict(self::$arr)) > 0) { |
|
171 | - $ret = ROCache::getSubdistrict(self::$arr); |
|
172 | - } else { |
|
173 | - $ret = self::getSubdistrict(self::$arr); |
|
174 | - } |
|
175 | - } |
|
176 | - } elseif ($cache_type == 'file') { |
|
177 | - $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
178 | - if ($ret == null) { |
|
179 | - self::exceptionCache(); |
|
180 | - } |
|
181 | - } else { |
|
182 | - $ret = self::getSubdistrict(self::$arr); |
|
183 | - } |
|
184 | - } else { |
|
185 | - $ret = self::getSubdistrict(self::$arr); |
|
186 | - } |
|
187 | - |
|
188 | - return $ret; |
|
189 | - } |
|
190 | - private static function internationalOriginData() |
|
191 | - { |
|
98 | + public static function province() |
|
99 | + { |
|
100 | + $ret = self::provinceData(); |
|
101 | + self::$return = $ret; |
|
102 | + |
|
103 | + return new static(); |
|
104 | + } |
|
105 | + |
|
106 | + public static function subDistrict() |
|
107 | + { |
|
108 | + $ret = self::subDistrictData(); |
|
109 | + self::$return = $ret; |
|
110 | + |
|
111 | + return new static(); |
|
112 | + } |
|
113 | + public static function internationalOrigin() |
|
114 | + { |
|
115 | + $ret = self::internationalOriginData(); |
|
116 | + self::$return = $ret; |
|
117 | + |
|
118 | + return new static(); |
|
119 | + } |
|
120 | + |
|
121 | + public static function city() |
|
122 | + { |
|
123 | + $ret = self::cityData(); |
|
124 | + self::$return = $ret; |
|
125 | + |
|
126 | + return new static(); |
|
127 | + } |
|
128 | + |
|
129 | + private static function setupConfig() |
|
130 | + { |
|
131 | + self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type')); |
|
132 | + self::$province = config('irfa.rajaongkir.province_table'); |
|
133 | + self::$city = config('irfa.rajaongkir.city_table'); |
|
134 | + } |
|
135 | + |
|
136 | + private static function provinceData() |
|
137 | + { |
|
138 | + if (function_exists('config') && function_exists('app')) { |
|
139 | + self::setupConfig(); |
|
140 | + $cache_type = self::$cacheType; |
|
141 | + if ($cache_type == 'database') { |
|
142 | + if (ROCache::checkProv()) { |
|
143 | + if (count(ROCache::getProv(self::$arr)) > 0) { |
|
144 | + $ret = ROCache::getProv(self::$arr); |
|
145 | + } else { |
|
146 | + $ret = self::get_province(self::$arr); |
|
147 | + } |
|
148 | + } |
|
149 | + } elseif ($cache_type == 'file') { |
|
150 | + $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
151 | + if ($ret == null) { |
|
152 | + self::exceptionCache(); |
|
153 | + } |
|
154 | + } else { |
|
155 | + $ret = self::get_province(self::$arr); |
|
156 | + } |
|
157 | + } else { |
|
158 | + $ret = self::get_province(self::$arr); |
|
159 | + } |
|
160 | + |
|
161 | + return $ret; |
|
162 | + } |
|
163 | + private static function subDistrictData() |
|
164 | + { |
|
165 | + if (function_exists('config') && function_exists('app')) { |
|
166 | + self::setupConfig(); |
|
167 | + $cache_type = self::$cacheType; |
|
168 | + if ($cache_type == 'database') { |
|
169 | + if (ROCache::checkProv()) { |
|
170 | + if (count(ROCache::getSubdistrict(self::$arr)) > 0) { |
|
171 | + $ret = ROCache::getSubdistrict(self::$arr); |
|
172 | + } else { |
|
173 | + $ret = self::getSubdistrict(self::$arr); |
|
174 | + } |
|
175 | + } |
|
176 | + } elseif ($cache_type == 'file') { |
|
177 | + $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
178 | + if ($ret == null) { |
|
179 | + self::exceptionCache(); |
|
180 | + } |
|
181 | + } else { |
|
182 | + $ret = self::getSubdistrict(self::$arr); |
|
183 | + } |
|
184 | + } else { |
|
185 | + $ret = self::getSubdistrict(self::$arr); |
|
186 | + } |
|
187 | + |
|
188 | + return $ret; |
|
189 | + } |
|
190 | + private static function internationalOriginData() |
|
191 | + { |
|
192 | 192 | |
193 | - $ret = self::get_international_origin(self::$arr); |
|
193 | + $ret = self::get_international_origin(self::$arr); |
|
194 | 194 | |
195 | 195 | |
196 | - return $ret; |
|
197 | - } |
|
198 | - private static function cityData() |
|
199 | - { |
|
200 | - if (function_exists('config') && function_exists('app')) { |
|
201 | - self::setupConfig(); |
|
202 | - $cache_type = self::$cacheType; |
|
203 | - if ($cache_type == 'database') { |
|
204 | - if (ROCache::checkCity()) { |
|
205 | - if (count(ROCache::getCity(self::$arr)) > 0) { |
|
206 | - $ret = ROCache::getCity(self::$arr); |
|
207 | - } else { |
|
208 | - $ret = self::get_city(self::$arr); |
|
209 | - } |
|
210 | - } |
|
211 | - } elseif ($cache_type == 'file') { |
|
212 | - $ret = ROCache::cacheFile(self::$city, self::$arr); |
|
213 | - if ($ret == null) { |
|
214 | - self::exceptionCache(); |
|
215 | - } |
|
216 | - } else { |
|
217 | - $ret = self::get_city(self::$arr); |
|
218 | - } |
|
219 | - } else { |
|
220 | - $ret = self::get_city(self::$arr); |
|
221 | - } |
|
222 | - |
|
223 | - return $ret; |
|
224 | - } |
|
225 | - |
|
226 | - private static function exceptionCache() |
|
227 | - { |
|
228 | - throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache'); |
|
229 | - |
|
230 | - return false; |
|
231 | - } |
|
196 | + return $ret; |
|
197 | + } |
|
198 | + private static function cityData() |
|
199 | + { |
|
200 | + if (function_exists('config') && function_exists('app')) { |
|
201 | + self::setupConfig(); |
|
202 | + $cache_type = self::$cacheType; |
|
203 | + if ($cache_type == 'database') { |
|
204 | + if (ROCache::checkCity()) { |
|
205 | + if (count(ROCache::getCity(self::$arr)) > 0) { |
|
206 | + $ret = ROCache::getCity(self::$arr); |
|
207 | + } else { |
|
208 | + $ret = self::get_city(self::$arr); |
|
209 | + } |
|
210 | + } |
|
211 | + } elseif ($cache_type == 'file') { |
|
212 | + $ret = ROCache::cacheFile(self::$city, self::$arr); |
|
213 | + if ($ret == null) { |
|
214 | + self::exceptionCache(); |
|
215 | + } |
|
216 | + } else { |
|
217 | + $ret = self::get_city(self::$arr); |
|
218 | + } |
|
219 | + } else { |
|
220 | + $ret = self::get_city(self::$arr); |
|
221 | + } |
|
222 | + |
|
223 | + return $ret; |
|
224 | + } |
|
225 | + |
|
226 | + private static function exceptionCache() |
|
227 | + { |
|
228 | + throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache'); |
|
229 | + |
|
230 | + return false; |
|
231 | + } |
|
232 | 232 | } |
@@ -52,16 +52,16 @@ |
||
52 | 52 | |
53 | 53 | public static function cachingSubDistrict() |
54 | 54 | { |
55 | - if(strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
55 | + if (strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
56 | 56 | { |
57 | 57 | echo "Tidak dapat mengambil SubDistrict dikarenakan akun yg anda pakai tipe starter."; |
58 | 58 | return true; |
59 | 59 | } |
60 | 60 | $get = self::cityData(); |
61 | 61 | $count = count($get); |
62 | - $i=0; |
|
62 | + $i = 0; |
|
63 | 63 | echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m"; |
64 | - foreach($get as $city){ |
|
64 | + foreach ($get as $city) { |
|
65 | 65 | $i++; |
66 | 66 | echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m"; |
67 | 67 | echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL; |