@@ -6,34 +6,34 @@ |
||
| 6 | 6 | |
| 7 | 7 | class RajaOngkirServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Register services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function register() |
|
| 15 | - { |
|
| 16 | - // |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * Register services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function register() |
|
| 15 | + { |
|
| 16 | + // |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Bootstrap services. |
|
| 21 | - * |
|
| 22 | - * @return void |
|
| 23 | - */ |
|
| 24 | - public function boot() |
|
| 25 | - { |
|
| 26 | - $this->publishes([ |
|
| 27 | - __DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php'), ], 'raja-ongkir'); |
|
| 19 | + /** |
|
| 20 | + * Bootstrap services. |
|
| 21 | + * |
|
| 22 | + * @return void |
|
| 23 | + */ |
|
| 24 | + public function boot() |
|
| 25 | + { |
|
| 26 | + $this->publishes([ |
|
| 27 | + __DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php'), ], 'raja-ongkir'); |
|
| 28 | 28 | |
| 29 | - $this->publishes([ |
|
| 30 | - __DIR__.'/../database/migrations/' => database_path('migrations'), |
|
| 31 | - ], 'raja-ongkir'); |
|
| 29 | + $this->publishes([ |
|
| 30 | + __DIR__.'/../database/migrations/' => database_path('migrations'), |
|
| 31 | + ], 'raja-ongkir'); |
|
| 32 | 32 | |
| 33 | - $this->publishes([__DIR__.'/../database/migrations/' => database_path('migrations'), |
|
| 34 | - ], 'raja-ongkir'); |
|
| 33 | + $this->publishes([__DIR__.'/../database/migrations/' => database_path('migrations'), |
|
| 34 | + ], 'raja-ongkir'); |
|
| 35 | 35 | |
| 36 | - $this->publishes([__DIR__.'/../console/' => app_path('console'), |
|
| 37 | - ], 'raja-ongkir'); |
|
| 38 | - } |
|
| 36 | + $this->publishes([__DIR__.'/../console/' => app_path('console'), |
|
| 37 | + ], 'raja-ongkir'); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -12,193 +12,193 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Api extends CacheCurl |
| 14 | 14 | { |
| 15 | - private static $account_type; |
|
| 16 | - private static $api_key; |
|
| 17 | - private static $url; |
|
| 18 | - private static $count = 0; |
|
| 19 | - |
|
| 20 | - public function __construct() |
|
| 21 | - { |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - private static function setup_option() |
|
| 25 | - { |
|
| 26 | - if (function_exists('config') and function_exists('app')) {//Load Config For Laravel |
|
| 27 | - self::$account_type = strtolower(config('irfa.rajaongkir.account_type')); |
|
| 28 | - self::$api_key = config('irfa.rajaongkir.api_key'); |
|
| 29 | - } else {//Load config For PHP Native |
|
| 30 | - require __DIR__.'../../../../config/config.php'; |
|
| 31 | - self::$account_type = strtolower($config['account_type']); |
|
| 32 | - self::$api_key = $config['api_key']; |
|
| 33 | - } |
|
| 34 | - if (self::$account_type == 'pro') { |
|
| 35 | - self::$url = 'https://pro.rajaongkir.com/api'; |
|
| 36 | - } else { |
|
| 37 | - self::$url = 'https://api.rajaongkir.com/'.self::$account_type; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - protected static function cacheProvince() |
|
| 42 | - { |
|
| 43 | - self::setup_option(); |
|
| 44 | - echo "Retrieving data from \033[96m".self::$url."...\033[0m".PHP_EOL; |
|
| 45 | - CacheCurl::caching(self::get_province())->province(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - protected static function cacheCity() |
|
| 49 | - { |
|
| 50 | - self::setup_option(); |
|
| 51 | - echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL; |
|
| 52 | - CacheCurl::caching(self::get_city())->city(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - protected static function get_province($arr = null) |
|
| 56 | - { |
|
| 57 | - if ($arr != null) { |
|
| 58 | - $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null; |
|
| 59 | - } else { |
|
| 60 | - $province_id = null; |
|
| 61 | - } |
|
| 62 | - self::setup_option(); |
|
| 63 | - $curl = curl_init(); |
|
| 64 | - curl_setopt_array($curl, [ |
|
| 65 | - CURLOPT_URL => self::$url.'/province'.$province_id, |
|
| 66 | - CURLOPT_RETURNTRANSFER => true, |
|
| 67 | - CURLOPT_ENCODING => '', |
|
| 68 | - CURLOPT_MAXREDIRS => 10, |
|
| 69 | - CURLOPT_TIMEOUT => 30, |
|
| 70 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 71 | - CURLOPT_CUSTOMREQUEST => 'GET', |
|
| 72 | - CURLOPT_HTTPHEADER => [ |
|
| 73 | - 'key: '.self::$api_key, |
|
| 74 | - ], |
|
| 75 | - ]); |
|
| 76 | - $response = curl_exec($curl); |
|
| 77 | - $err = curl_error($curl); |
|
| 78 | - |
|
| 79 | - curl_close($curl); |
|
| 80 | - |
|
| 81 | - if ($err) { |
|
| 82 | - echo "Can't connect to server, please check your internet connection."; |
|
| 83 | - exit(); |
|
| 84 | - } else { |
|
| 85 | - $json = json_decode($response, false)->rajaongkir; |
|
| 86 | - if ($json->status->code == '400') { |
|
| 87 | - throw new Exception($json->status->description); |
|
| 88 | - } else { |
|
| 89 | - $res = $json->results; |
|
| 90 | - |
|
| 91 | - return $res; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - protected static function get_city($arr = null) |
|
| 97 | - { |
|
| 98 | - if ($arr != null) { |
|
| 99 | - $province_id = array_key_exists('province_id', $arr) ? '?province='.$arr['province_id'] : null; |
|
| 100 | - } else { |
|
| 101 | - $province_id = null; |
|
| 102 | - } |
|
| 103 | - self::setup_option(); |
|
| 104 | - $curl = curl_init(); |
|
| 105 | - curl_setopt_array($curl, [ |
|
| 106 | - CURLOPT_URL => self::$url.'/city'.$province_id, |
|
| 107 | - CURLOPT_RETURNTRANSFER => true, |
|
| 108 | - CURLOPT_ENCODING => '', |
|
| 109 | - CURLOPT_MAXREDIRS => 10, |
|
| 110 | - CURLOPT_TIMEOUT => 30, |
|
| 111 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 112 | - CURLOPT_CUSTOMREQUEST => 'GET', |
|
| 113 | - CURLOPT_HTTPHEADER => [ |
|
| 114 | - 'key: '.self::$api_key, |
|
| 115 | - ], |
|
| 116 | - ]); |
|
| 117 | - $response = curl_exec($curl); |
|
| 118 | - $err = curl_error($curl); |
|
| 119 | - |
|
| 120 | - curl_close($curl); |
|
| 121 | - |
|
| 122 | - if ($err) { |
|
| 123 | - echo "Can't connect to server, please check your internet connection."; |
|
| 124 | - exit(); |
|
| 125 | - } else { |
|
| 126 | - $json = json_decode($response, false)->rajaongkir; |
|
| 127 | - if ($json->status->code == '400') { |
|
| 128 | - throw new Exception($json->status->description); |
|
| 129 | - } else { |
|
| 130 | - $res = $json->results; |
|
| 131 | - |
|
| 132 | - return $res; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - protected static function get_courier($arr) |
|
| 138 | - { |
|
| 139 | - $origin = $arr['origin']; |
|
| 140 | - $destination = $arr['destination']; |
|
| 141 | - $weight = $arr['weight']; |
|
| 142 | - $courier = $arr['courier']; |
|
| 143 | - $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
| 144 | - |
|
| 145 | - return $res; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - protected static function get_cost_details($arr) |
|
| 149 | - { |
|
| 150 | - $origin = $arr['origin']; |
|
| 151 | - $destination = $arr['destination']; |
|
| 152 | - $weight = $arr['weight']; |
|
| 153 | - $courier = $arr['courier']; |
|
| 154 | - $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
| 155 | - |
|
| 156 | - return $res[0]->costs; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - private static function curl_cost_get($origin, $destination, $weight, $courier) |
|
| 160 | - { |
|
| 161 | - $curl = curl_init(); |
|
| 162 | - |
|
| 163 | - curl_setopt_array($curl, self::curl_cost_option($origin, $destination, $weight, $courier)); |
|
| 164 | - |
|
| 165 | - $response = curl_exec($curl); |
|
| 166 | - $err = curl_error($curl); |
|
| 167 | - |
|
| 168 | - curl_close($curl); |
|
| 169 | - |
|
| 170 | - if ($err) { |
|
| 171 | - echo "Can't connect to server, please check your internet connection."; |
|
| 172 | - exit(); |
|
| 173 | - } else { |
|
| 174 | - $json = json_decode($response, false)->rajaongkir; |
|
| 175 | - if ($json->status->code == '400') { |
|
| 176 | - throw new Exception($json->status->description); |
|
| 177 | - } else { |
|
| 178 | - $res = $json->results; |
|
| 179 | - |
|
| 180 | - return $res; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - private static function curl_cost_option($origin, $destination, $weight, $courier) |
|
| 186 | - { |
|
| 187 | - self::setup_option(); |
|
| 188 | - |
|
| 189 | - return [ |
|
| 190 | - CURLOPT_URL => self::$url.'/cost', |
|
| 191 | - CURLOPT_RETURNTRANSFER => true, |
|
| 192 | - CURLOPT_ENCODING => '', |
|
| 193 | - CURLOPT_MAXREDIRS => 10, |
|
| 194 | - CURLOPT_TIMEOUT => 30, |
|
| 195 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 196 | - CURLOPT_CUSTOMREQUEST => 'POST', |
|
| 197 | - CURLOPT_POSTFIELDS => 'origin='.$origin.'&destination='.$destination.'&weight='.$weight.'&courier='.strtolower($courier), |
|
| 198 | - CURLOPT_HTTPHEADER => [ |
|
| 199 | - 'content-type: application/x-www-form-urlencoded', |
|
| 200 | - 'key: '.self::$api_key, |
|
| 201 | - ], |
|
| 202 | - ]; |
|
| 203 | - } |
|
| 15 | + private static $account_type; |
|
| 16 | + private static $api_key; |
|
| 17 | + private static $url; |
|
| 18 | + private static $count = 0; |
|
| 19 | + |
|
| 20 | + public function __construct() |
|
| 21 | + { |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + private static function setup_option() |
|
| 25 | + { |
|
| 26 | + if (function_exists('config') and function_exists('app')) {//Load Config For Laravel |
|
| 27 | + self::$account_type = strtolower(config('irfa.rajaongkir.account_type')); |
|
| 28 | + self::$api_key = config('irfa.rajaongkir.api_key'); |
|
| 29 | + } else {//Load config For PHP Native |
|
| 30 | + require __DIR__.'../../../../config/config.php'; |
|
| 31 | + self::$account_type = strtolower($config['account_type']); |
|
| 32 | + self::$api_key = $config['api_key']; |
|
| 33 | + } |
|
| 34 | + if (self::$account_type == 'pro') { |
|
| 35 | + self::$url = 'https://pro.rajaongkir.com/api'; |
|
| 36 | + } else { |
|
| 37 | + self::$url = 'https://api.rajaongkir.com/'.self::$account_type; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + protected static function cacheProvince() |
|
| 42 | + { |
|
| 43 | + self::setup_option(); |
|
| 44 | + echo "Retrieving data from \033[96m".self::$url."...\033[0m".PHP_EOL; |
|
| 45 | + CacheCurl::caching(self::get_province())->province(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + protected static function cacheCity() |
|
| 49 | + { |
|
| 50 | + self::setup_option(); |
|
| 51 | + echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL; |
|
| 52 | + CacheCurl::caching(self::get_city())->city(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + protected static function get_province($arr = null) |
|
| 56 | + { |
|
| 57 | + if ($arr != null) { |
|
| 58 | + $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null; |
|
| 59 | + } else { |
|
| 60 | + $province_id = null; |
|
| 61 | + } |
|
| 62 | + self::setup_option(); |
|
| 63 | + $curl = curl_init(); |
|
| 64 | + curl_setopt_array($curl, [ |
|
| 65 | + CURLOPT_URL => self::$url.'/province'.$province_id, |
|
| 66 | + CURLOPT_RETURNTRANSFER => true, |
|
| 67 | + CURLOPT_ENCODING => '', |
|
| 68 | + CURLOPT_MAXREDIRS => 10, |
|
| 69 | + CURLOPT_TIMEOUT => 30, |
|
| 70 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 71 | + CURLOPT_CUSTOMREQUEST => 'GET', |
|
| 72 | + CURLOPT_HTTPHEADER => [ |
|
| 73 | + 'key: '.self::$api_key, |
|
| 74 | + ], |
|
| 75 | + ]); |
|
| 76 | + $response = curl_exec($curl); |
|
| 77 | + $err = curl_error($curl); |
|
| 78 | + |
|
| 79 | + curl_close($curl); |
|
| 80 | + |
|
| 81 | + if ($err) { |
|
| 82 | + echo "Can't connect to server, please check your internet connection."; |
|
| 83 | + exit(); |
|
| 84 | + } else { |
|
| 85 | + $json = json_decode($response, false)->rajaongkir; |
|
| 86 | + if ($json->status->code == '400') { |
|
| 87 | + throw new Exception($json->status->description); |
|
| 88 | + } else { |
|
| 89 | + $res = $json->results; |
|
| 90 | + |
|
| 91 | + return $res; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + protected static function get_city($arr = null) |
|
| 97 | + { |
|
| 98 | + if ($arr != null) { |
|
| 99 | + $province_id = array_key_exists('province_id', $arr) ? '?province='.$arr['province_id'] : null; |
|
| 100 | + } else { |
|
| 101 | + $province_id = null; |
|
| 102 | + } |
|
| 103 | + self::setup_option(); |
|
| 104 | + $curl = curl_init(); |
|
| 105 | + curl_setopt_array($curl, [ |
|
| 106 | + CURLOPT_URL => self::$url.'/city'.$province_id, |
|
| 107 | + CURLOPT_RETURNTRANSFER => true, |
|
| 108 | + CURLOPT_ENCODING => '', |
|
| 109 | + CURLOPT_MAXREDIRS => 10, |
|
| 110 | + CURLOPT_TIMEOUT => 30, |
|
| 111 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 112 | + CURLOPT_CUSTOMREQUEST => 'GET', |
|
| 113 | + CURLOPT_HTTPHEADER => [ |
|
| 114 | + 'key: '.self::$api_key, |
|
| 115 | + ], |
|
| 116 | + ]); |
|
| 117 | + $response = curl_exec($curl); |
|
| 118 | + $err = curl_error($curl); |
|
| 119 | + |
|
| 120 | + curl_close($curl); |
|
| 121 | + |
|
| 122 | + if ($err) { |
|
| 123 | + echo "Can't connect to server, please check your internet connection."; |
|
| 124 | + exit(); |
|
| 125 | + } else { |
|
| 126 | + $json = json_decode($response, false)->rajaongkir; |
|
| 127 | + if ($json->status->code == '400') { |
|
| 128 | + throw new Exception($json->status->description); |
|
| 129 | + } else { |
|
| 130 | + $res = $json->results; |
|
| 131 | + |
|
| 132 | + return $res; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + protected static function get_courier($arr) |
|
| 138 | + { |
|
| 139 | + $origin = $arr['origin']; |
|
| 140 | + $destination = $arr['destination']; |
|
| 141 | + $weight = $arr['weight']; |
|
| 142 | + $courier = $arr['courier']; |
|
| 143 | + $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
| 144 | + |
|
| 145 | + return $res; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + protected static function get_cost_details($arr) |
|
| 149 | + { |
|
| 150 | + $origin = $arr['origin']; |
|
| 151 | + $destination = $arr['destination']; |
|
| 152 | + $weight = $arr['weight']; |
|
| 153 | + $courier = $arr['courier']; |
|
| 154 | + $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
| 155 | + |
|
| 156 | + return $res[0]->costs; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + private static function curl_cost_get($origin, $destination, $weight, $courier) |
|
| 160 | + { |
|
| 161 | + $curl = curl_init(); |
|
| 162 | + |
|
| 163 | + curl_setopt_array($curl, self::curl_cost_option($origin, $destination, $weight, $courier)); |
|
| 164 | + |
|
| 165 | + $response = curl_exec($curl); |
|
| 166 | + $err = curl_error($curl); |
|
| 167 | + |
|
| 168 | + curl_close($curl); |
|
| 169 | + |
|
| 170 | + if ($err) { |
|
| 171 | + echo "Can't connect to server, please check your internet connection."; |
|
| 172 | + exit(); |
|
| 173 | + } else { |
|
| 174 | + $json = json_decode($response, false)->rajaongkir; |
|
| 175 | + if ($json->status->code == '400') { |
|
| 176 | + throw new Exception($json->status->description); |
|
| 177 | + } else { |
|
| 178 | + $res = $json->results; |
|
| 179 | + |
|
| 180 | + return $res; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + private static function curl_cost_option($origin, $destination, $weight, $courier) |
|
| 186 | + { |
|
| 187 | + self::setup_option(); |
|
| 188 | + |
|
| 189 | + return [ |
|
| 190 | + CURLOPT_URL => self::$url.'/cost', |
|
| 191 | + CURLOPT_RETURNTRANSFER => true, |
|
| 192 | + CURLOPT_ENCODING => '', |
|
| 193 | + CURLOPT_MAXREDIRS => 10, |
|
| 194 | + CURLOPT_TIMEOUT => 30, |
|
| 195 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 196 | + CURLOPT_CUSTOMREQUEST => 'POST', |
|
| 197 | + CURLOPT_POSTFIELDS => 'origin='.$origin.'&destination='.$destination.'&weight='.$weight.'&courier='.strtolower($courier), |
|
| 198 | + CURLOPT_HTTPHEADER => [ |
|
| 199 | + 'content-type: application/x-www-form-urlencoded', |
|
| 200 | + 'key: '.self::$api_key, |
|
| 201 | + ], |
|
| 202 | + ]; |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -12,114 +12,114 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Ongkir extends Api |
| 14 | 14 | { |
| 15 | - private static $arr; |
|
| 16 | - private static $return; |
|
| 17 | - |
|
| 18 | - public static function find($arr) |
|
| 19 | - { |
|
| 20 | - if (is_array($arr)) { |
|
| 21 | - self::$arr = $arr; |
|
| 22 | - |
|
| 23 | - return new static(); |
|
| 24 | - } else { |
|
| 25 | - throw new Exception('Parameter must be an array.'); |
|
| 26 | - |
|
| 27 | - return false; |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public static function get() |
|
| 32 | - { |
|
| 33 | - if (empty(self::$return)) { |
|
| 34 | - throw new Exception('Data is not defined.'); |
|
| 35 | - |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return self::$return; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public static function cachingProvince() |
|
| 43 | - { |
|
| 44 | - self::cacheProvince(); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public static function cachingCity() |
|
| 48 | - { |
|
| 49 | - self::cacheCity(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public static function costDetails() |
|
| 53 | - { |
|
| 54 | - self::$return = self::get_cost_details(self::$arr); |
|
| 55 | - |
|
| 56 | - return new static(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public static function courier() |
|
| 60 | - { |
|
| 61 | - self::$return = self::get_courier(self::$arr); |
|
| 62 | - |
|
| 63 | - return new static(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public static function province() |
|
| 67 | - { |
|
| 68 | - if (function_exists('config') and function_exists('app')) { |
|
| 69 | - $cache_type = strtolower(config('irfa.rajaongkir.cache_type')); |
|
| 70 | - if ($cache_type == 'database') { |
|
| 71 | - if (ROCache::checkProv()) { |
|
| 72 | - if (count(ROCache::getProv(self::$arr)) > 0) { |
|
| 73 | - $ret = ROCache::getProv(self::$arr); |
|
| 74 | - } else { |
|
| 75 | - $ret = self::get_province(self::$arr); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } elseif ($cache_type == 'file') { |
|
| 79 | - $ret = ROCache::cacheFile(config('irfa.rajaongkir.province_table'), self::$arr); |
|
| 80 | - if ($ret == null) { |
|
| 81 | - throw new Exception('Cache is empty.'); |
|
| 82 | - |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 85 | - } else { |
|
| 86 | - $ret = self::get_province(self::$arr); |
|
| 87 | - } |
|
| 88 | - } else { |
|
| 89 | - $ret = self::get_province(self::$arr); |
|
| 90 | - } |
|
| 91 | - self::$return = $ret; |
|
| 92 | - |
|
| 93 | - return new static(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public static function city() |
|
| 97 | - { |
|
| 98 | - if (function_exists('config') and function_exists('app')) { |
|
| 99 | - $cache_type = strtolower(config('irfa.rajaongkir.cache_type')); |
|
| 100 | - if ($cache_type == 'database') { |
|
| 101 | - if (ROCache::checkCity()) { |
|
| 102 | - if (count(ROCache::getCity(self::$arr)) > 0) { |
|
| 103 | - $ret = ROCache::getCity(self::$arr); |
|
| 104 | - } else { |
|
| 105 | - $ret = self::get_city(self::$arr); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } elseif ($cache_type == 'file') { |
|
| 109 | - $ret = ROCache::cacheFile(config('irfa.rajaongkir.city_table'), self::$arr); |
|
| 110 | - if ($ret == null) { |
|
| 111 | - throw new Exception('Cache is empty. Try php artisan raja-ongkir:cache'); |
|
| 112 | - |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - } else { |
|
| 116 | - $ret = self::get_city(self::$arr); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $ret = self::get_city(self::$arr); |
|
| 120 | - } |
|
| 121 | - self::$return = $ret; |
|
| 122 | - |
|
| 123 | - return new static(); |
|
| 124 | - } |
|
| 15 | + private static $arr; |
|
| 16 | + private static $return; |
|
| 17 | + |
|
| 18 | + public static function find($arr) |
|
| 19 | + { |
|
| 20 | + if (is_array($arr)) { |
|
| 21 | + self::$arr = $arr; |
|
| 22 | + |
|
| 23 | + return new static(); |
|
| 24 | + } else { |
|
| 25 | + throw new Exception('Parameter must be an array.'); |
|
| 26 | + |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public static function get() |
|
| 32 | + { |
|
| 33 | + if (empty(self::$return)) { |
|
| 34 | + throw new Exception('Data is not defined.'); |
|
| 35 | + |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return self::$return; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public static function cachingProvince() |
|
| 43 | + { |
|
| 44 | + self::cacheProvince(); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public static function cachingCity() |
|
| 48 | + { |
|
| 49 | + self::cacheCity(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public static function costDetails() |
|
| 53 | + { |
|
| 54 | + self::$return = self::get_cost_details(self::$arr); |
|
| 55 | + |
|
| 56 | + return new static(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public static function courier() |
|
| 60 | + { |
|
| 61 | + self::$return = self::get_courier(self::$arr); |
|
| 62 | + |
|
| 63 | + return new static(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public static function province() |
|
| 67 | + { |
|
| 68 | + if (function_exists('config') and function_exists('app')) { |
|
| 69 | + $cache_type = strtolower(config('irfa.rajaongkir.cache_type')); |
|
| 70 | + if ($cache_type == 'database') { |
|
| 71 | + if (ROCache::checkProv()) { |
|
| 72 | + if (count(ROCache::getProv(self::$arr)) > 0) { |
|
| 73 | + $ret = ROCache::getProv(self::$arr); |
|
| 74 | + } else { |
|
| 75 | + $ret = self::get_province(self::$arr); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } elseif ($cache_type == 'file') { |
|
| 79 | + $ret = ROCache::cacheFile(config('irfa.rajaongkir.province_table'), self::$arr); |
|
| 80 | + if ($ret == null) { |
|
| 81 | + throw new Exception('Cache is empty.'); |
|
| 82 | + |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | + } else { |
|
| 86 | + $ret = self::get_province(self::$arr); |
|
| 87 | + } |
|
| 88 | + } else { |
|
| 89 | + $ret = self::get_province(self::$arr); |
|
| 90 | + } |
|
| 91 | + self::$return = $ret; |
|
| 92 | + |
|
| 93 | + return new static(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public static function city() |
|
| 97 | + { |
|
| 98 | + if (function_exists('config') and function_exists('app')) { |
|
| 99 | + $cache_type = strtolower(config('irfa.rajaongkir.cache_type')); |
|
| 100 | + if ($cache_type == 'database') { |
|
| 101 | + if (ROCache::checkCity()) { |
|
| 102 | + if (count(ROCache::getCity(self::$arr)) > 0) { |
|
| 103 | + $ret = ROCache::getCity(self::$arr); |
|
| 104 | + } else { |
|
| 105 | + $ret = self::get_city(self::$arr); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } elseif ($cache_type == 'file') { |
|
| 109 | + $ret = ROCache::cacheFile(config('irfa.rajaongkir.city_table'), self::$arr); |
|
| 110 | + if ($ret == null) { |
|
| 111 | + throw new Exception('Cache is empty. Try php artisan raja-ongkir:cache'); |
|
| 112 | + |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + } else { |
|
| 116 | + $ret = self::get_city(self::$arr); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $ret = self::get_city(self::$arr); |
|
| 120 | + } |
|
| 121 | + self::$return = $ret; |
|
| 122 | + |
|
| 123 | + return new static(); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - /* |
|
| 4 | + /* |
|
| 5 | 5 | |-------------------------------------------------------------------------- |
| 6 | 6 | | End Point Api ( Server Configuration ) |
| 7 | 7 | |-------------------------------------------------------------------------- |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | | Pro : http://pro.rajaongkir.com/api |
| 12 | 12 | | |
| 13 | 13 | */ |
| 14 | - 'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'), |
|
| 15 | - /* |
|
| 14 | + 'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'), |
|
| 15 | + /* |
|
| 16 | 16 | |-------------------------------------------------------------------------- |
| 17 | 17 | | API key |
| 18 | 18 | |-------------------------------------------------------------------------- |
@@ -20,19 +20,19 @@ discard block |
||
| 20 | 20 | | |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | - 'api_key' => env('RAJAONGKIR_API_KEY', 'your-api-key'), |
|
| 24 | - /* |
|
| 23 | + 'api_key' => env('RAJAONGKIR_API_KEY', 'your-api-key'), |
|
| 24 | + /* |
|
| 25 | 25 | |-------------------------------------------------------------------------- |
| 26 | 26 | | For Caching |
| 27 | 27 | |-------------------------------------------------------------------------- |
| 28 | 28 | | You are free to change the cache configuration. |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | - 'province_table' => env('RAJAONGKIR_PROV_TABLE', 'ro_province'), |
|
| 31 | + 'province_table' => env('RAJAONGKIR_PROV_TABLE', 'ro_province'), |
|
| 32 | 32 | |
| 33 | - 'city_table' => env('RAJAONGKIR_CITY_TABLE', 'ro_city'), |
|
| 33 | + 'city_table' => env('RAJAONGKIR_CITY_TABLE', 'ro_city'), |
|
| 34 | 34 | |
| 35 | - // Cache supported database,and file, default value : database |
|
| 36 | - 'cache_type' => env('RAJAONGKIR_CACHE', 'file'), |
|
| 35 | + // Cache supported database,and file, default value : database |
|
| 36 | + 'cache_type' => env('RAJAONGKIR_CACHE', 'file'), |
|
| 37 | 37 | |
| 38 | 38 | ]; |
@@ -7,37 +7,37 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ROCity extends Command |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The name and signature of the console command. |
|
| 12 | - * |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $signature = 'raja-ongkir:city-cache'; |
|
| 10 | + /** |
|
| 11 | + * The name and signature of the console command. |
|
| 12 | + * |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $signature = 'raja-ongkir:city-cache'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The console command description. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $description = 'Create city list cache for faster loading city list'; |
|
| 17 | + /** |
|
| 18 | + * The console command description. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $description = 'Create city list cache for faster loading city list'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Create a new command instance. |
|
| 26 | - * |
|
| 27 | - * @return void |
|
| 28 | - */ |
|
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - parent::__construct(); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * Create a new command instance. |
|
| 26 | + * |
|
| 27 | + * @return void |
|
| 28 | + */ |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + parent::__construct(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Execute the console command. |
|
| 36 | - * |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 39 | - public function handle() |
|
| 40 | - { |
|
| 41 | - RajaOngkir::cachingCity(); |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * Execute the console command. |
|
| 36 | + * |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | + public function handle() |
|
| 40 | + { |
|
| 41 | + RajaOngkir::cachingCity(); |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -8,51 +8,51 @@ |
||
| 8 | 8 | |
| 9 | 9 | class RORefresh extends Command |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The name and signature of the console command. |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $signature = 'raja-ongkir:refresh'; |
|
| 11 | + /** |
|
| 12 | + * The name and signature of the console command. |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $signature = 'raja-ongkir:refresh'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The console command description. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $description = 'Refresh Cache'; |
|
| 18 | + /** |
|
| 19 | + * The console command description. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $description = 'Refresh Cache'; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Create a new command instance. |
|
| 27 | - * |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - parent::__construct(); |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * Create a new command instance. |
|
| 27 | + * |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + parent::__construct(); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Execute the console command. |
|
| 37 | - * |
|
| 38 | - * @return mixed |
|
| 39 | - */ |
|
| 40 | - public function handle() |
|
| 41 | - { |
|
| 42 | - echo '---------------------'.PHP_EOL; |
|
| 43 | - echo'Refresh Cache'.PHP_EOL; |
|
| 44 | - echo'---------------------'.PHP_EOL; |
|
| 45 | - ROCache::clearCache(); |
|
| 46 | - sleep(1); //Cooling Down |
|
| 47 | - echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 48 | - echo'Province Caching'.PHP_EOL; |
|
| 49 | - echo'---------------------'.PHP_EOL; |
|
| 50 | - RajaOngkir::cachingProvince(); |
|
| 51 | - echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 52 | - sleep(1); //Cooling Down |
|
| 53 | - echo'City Caching'.PHP_EOL; |
|
| 54 | - echo '---------------------'.PHP_EOL; |
|
| 55 | - RajaOngkir::cachingCity(); |
|
| 56 | - echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 57 | - } |
|
| 35 | + /** |
|
| 36 | + * Execute the console command. |
|
| 37 | + * |
|
| 38 | + * @return mixed |
|
| 39 | + */ |
|
| 40 | + public function handle() |
|
| 41 | + { |
|
| 42 | + echo '---------------------'.PHP_EOL; |
|
| 43 | + echo'Refresh Cache'.PHP_EOL; |
|
| 44 | + echo'---------------------'.PHP_EOL; |
|
| 45 | + ROCache::clearCache(); |
|
| 46 | + sleep(1); //Cooling Down |
|
| 47 | + echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 48 | + echo'Province Caching'.PHP_EOL; |
|
| 49 | + echo'---------------------'.PHP_EOL; |
|
| 50 | + RajaOngkir::cachingProvince(); |
|
| 51 | + echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 52 | + sleep(1); //Cooling Down |
|
| 53 | + echo'City Caching'.PHP_EOL; |
|
| 54 | + echo '---------------------'.PHP_EOL; |
|
| 55 | + RajaOngkir::cachingCity(); |
|
| 56 | + echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -7,46 +7,46 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ROCacheAll extends Command |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The name and signature of the console command. |
|
| 12 | - * |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $signature = 'raja-ongkir:cache'; |
|
| 10 | + /** |
|
| 11 | + * The name and signature of the console command. |
|
| 12 | + * |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $signature = 'raja-ongkir:cache'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The console command description. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $description = 'Create City and Province list cache for faster loading city and province. '; |
|
| 17 | + /** |
|
| 18 | + * The console command description. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $description = 'Create City and Province list cache for faster loading city and province. '; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Create a new command instance. |
|
| 26 | - * |
|
| 27 | - * @return void |
|
| 28 | - */ |
|
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - parent::__construct(); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * Create a new command instance. |
|
| 26 | + * |
|
| 27 | + * @return void |
|
| 28 | + */ |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + parent::__construct(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Execute the console command. |
|
| 36 | - * |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 39 | - public function handle() |
|
| 40 | - { |
|
| 41 | - echo '---------------------'.PHP_EOL; |
|
| 42 | - echo'Province Caching'.PHP_EOL; |
|
| 43 | - echo'---------------------'.PHP_EOL; |
|
| 44 | - RajaOngkir::cachingProvince(); |
|
| 45 | - echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 46 | - sleep(1); //Cooling Down |
|
| 47 | - echo'City Caching'.PHP_EOL; |
|
| 48 | - echo '---------------------'.PHP_EOL; |
|
| 49 | - RajaOngkir::cachingCity(); |
|
| 50 | - echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 51 | - } |
|
| 34 | + /** |
|
| 35 | + * Execute the console command. |
|
| 36 | + * |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | + public function handle() |
|
| 40 | + { |
|
| 41 | + echo '---------------------'.PHP_EOL; |
|
| 42 | + echo'Province Caching'.PHP_EOL; |
|
| 43 | + echo'---------------------'.PHP_EOL; |
|
| 44 | + RajaOngkir::cachingProvince(); |
|
| 45 | + echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 46 | + sleep(1); //Cooling Down |
|
| 47 | + echo'City Caching'.PHP_EOL; |
|
| 48 | + echo '---------------------'.PHP_EOL; |
|
| 49 | + RajaOngkir::cachingCity(); |
|
| 50 | + echo PHP_EOL.'---------------------'.PHP_EOL; |
|
| 51 | + } |
|
| 52 | 52 | } |