@@ -44,7 +44,7 @@ |
||
| 44 | 44 | echo"---------------------".PHP_EOL; |
| 45 | 45 | RajaOngkir::cachingProvince(); |
| 46 | 46 | echo PHP_EOL."---------------------".PHP_EOL; |
| 47 | - sleep(1);//Cooling Down |
|
| 47 | + sleep(1); //Cooling Down |
|
| 48 | 48 | echo"City Caching".PHP_EOL; |
| 49 | 49 | echo "---------------------".PHP_EOL; |
| 50 | 50 | RajaOngkir::cachingCity(); |
@@ -43,13 +43,13 @@ |
||
| 43 | 43 | echo"Refresh Cache".PHP_EOL; |
| 44 | 44 | echo"---------------------".PHP_EOL; |
| 45 | 45 | ROCache::clearCache(); |
| 46 | - sleep(1);//Cooling Down |
|
| 46 | + sleep(1); //Cooling Down |
|
| 47 | 47 | echo PHP_EOL."---------------------".PHP_EOL; |
| 48 | 48 | echo"Province Caching".PHP_EOL; |
| 49 | 49 | echo"---------------------".PHP_EOL; |
| 50 | 50 | RajaOngkir::cachingProvince(); |
| 51 | 51 | echo PHP_EOL."---------------------".PHP_EOL; |
| 52 | - sleep(1);//Cooling Down |
|
| 52 | + sleep(1); //Cooling Down |
|
| 53 | 53 | echo"City Caching".PHP_EOL; |
| 54 | 54 | echo "---------------------".PHP_EOL; |
| 55 | 55 | RajaOngkir::cachingCity(); |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('ro_city', function (Blueprint $table) { |
|
| 17 | - $table->string('city_id',20)->primary(); |
|
| 18 | - $table->string('province_id',20); |
|
| 19 | - $table->string('province',120)->nullable(); |
|
| 20 | - $table->string('type',60)->nullable(); |
|
| 21 | - $table->string('city_name',128)->nullable(); |
|
| 22 | - $table->string('postal_code',15)->nullable(); |
|
| 16 | + Schema::create('ro_city', function(Blueprint $table) { |
|
| 17 | + $table->string('city_id', 20)->primary(); |
|
| 18 | + $table->string('province_id', 20); |
|
| 19 | + $table->string('province', 120)->nullable(); |
|
| 20 | + $table->string('type', 60)->nullable(); |
|
| 21 | + $table->string('city_name', 128)->nullable(); |
|
| 22 | + $table->string('postal_code', 15)->nullable(); |
|
| 23 | 23 | $table->timestamps(); |
| 24 | 24 | |
| 25 | 25 | }); |
@@ -13,9 +13,9 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('ro_province', function (Blueprint $table) { |
|
| 17 | - $table->string('province_id',20)->primary(); |
|
| 18 | - $table->string('province',255)->nullable(); |
|
| 16 | + Schema::create('ro_province', function(Blueprint $table) { |
|
| 17 | + $table->string('province_id', 20)->primary(); |
|
| 18 | + $table->string('province', 255)->nullable(); |
|
| 19 | 19 | $table->timestamps(); |
| 20 | 20 | }); |
| 21 | 21 | } |
@@ -46,6 +46,6 @@ |
||
| 46 | 46 | $base = log($size, 1024); |
| 47 | 47 | $suffixes = array('B', 'KB', 'MB', 'GB', 'TB'); |
| 48 | 48 | |
| 49 | - return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)]; |
|
| 49 | + return round(pow(1024, $base - floor($base)), $precision).' '.$suffixes[floor($base)]; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |
@@ -25,16 +25,16 @@ |
||
| 25 | 25 | { |
| 26 | 26 | |
| 27 | 27 | $this->publishes([ |
| 28 | - __DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php')],'raja-ongkir'); |
|
| 28 | + __DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php')], 'raja-ongkir'); |
|
| 29 | 29 | |
| 30 | 30 | $this->publishes([ |
| 31 | 31 | __DIR__.'/../database/migrations/' => database_path('migrations') |
| 32 | 32 | ], 'raja-ongkir'); |
| 33 | 33 | |
| 34 | - $this->publishes([ __DIR__.'/../database/migrations/' => database_path('migrations') |
|
| 34 | + $this->publishes([__DIR__.'/../database/migrations/' => database_path('migrations') |
|
| 35 | 35 | ], 'raja-ongkir'); |
| 36 | 36 | |
| 37 | - $this->publishes([ __DIR__.'/../console/' => app_path('console') |
|
| 37 | + $this->publishes([__DIR__.'/../console/' => app_path('console') |
|
| 38 | 38 | ], 'raja-ongkir'); |
| 39 | 39 | |
| 40 | 40 | |
@@ -114,41 +114,41 @@ discard block |
||
| 114 | 114 | echo "Can't connect to server, please check your internet connection."; |
| 115 | 115 | exit(); |
| 116 | 116 | } else { |
| 117 | - $json = json_decode($response,false)->rajaongkir; |
|
| 118 | - if($json->status->code == "400"){ |
|
| 117 | + $json = json_decode($response, false)->rajaongkir; |
|
| 118 | + if ($json->status->code == "400") { |
|
| 119 | 119 | throw new Exception($json->status->description); |
| 120 | - } else{ |
|
| 120 | + } else { |
|
| 121 | 121 | $res = $json->results; |
| 122 | 122 | return $res; |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | - protected static function get_courier($arr){ |
|
| 126 | + protected static function get_courier($arr) { |
|
| 127 | 127 | $origin = $arr['origin']; |
| 128 | 128 | $destination = $arr['destination']; |
| 129 | 129 | $weight = $arr['weight']; |
| 130 | 130 | $courier = $arr['courier']; |
| 131 | - $res = self::curl_cost_get($origin,$destination,$weight,$courier); |
|
| 131 | + $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
| 132 | 132 | |
| 133 | 133 | return $res; |
| 134 | 134 | |
| 135 | 135 | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - protected static function get_cost_details($arr){ |
|
| 138 | + protected static function get_cost_details($arr) { |
|
| 139 | 139 | $origin = $arr['origin']; |
| 140 | 140 | $destination = $arr['destination']; |
| 141 | 141 | $weight = $arr['weight']; |
| 142 | 142 | $courier = $arr['courier']; |
| 143 | - $res = self::curl_cost_get($origin,$destination,$weight,$courier); |
|
| 143 | + $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
| 144 | 144 | |
| 145 | 145 | return $res{0}->costs; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - private static function curl_cost_get($origin,$destination,$weight,$courier){ |
|
| 148 | + private static function curl_cost_get($origin, $destination, $weight, $courier) { |
|
| 149 | 149 | $curl = curl_init(); |
| 150 | 150 | |
| 151 | - curl_setopt_array($curl, self::curl_cost_option($origin,$destination,$weight,$courier)); |
|
| 151 | + curl_setopt_array($curl, self::curl_cost_option($origin, $destination, $weight, $courier)); |
|
| 152 | 152 | |
| 153 | 153 | $response = curl_exec($curl); |
| 154 | 154 | $err = curl_error($curl); |
@@ -159,17 +159,17 @@ discard block |
||
| 159 | 159 | echo "Can't connect to server, please check your internet connection."; |
| 160 | 160 | exit(); |
| 161 | 161 | } else { |
| 162 | - $json = json_decode($response,false)->rajaongkir; |
|
| 163 | - if($json->status->code == "400"){ |
|
| 162 | + $json = json_decode($response, false)->rajaongkir; |
|
| 163 | + if ($json->status->code == "400") { |
|
| 164 | 164 | throw new Exception($json->status->description); |
| 165 | - } else{ |
|
| 165 | + } else { |
|
| 166 | 166 | $res = $json->results; |
| 167 | 167 | return $res; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | - private static function curl_cost_option($origin,$destination,$weight,$courier){ |
|
| 172 | + private static function curl_cost_option($origin, $destination, $weight, $courier) { |
|
| 173 | 173 | self::setup_option(); |
| 174 | 174 | return array( |
| 175 | 175 | CURLOPT_URL => self::$url.'/cost', |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | | Pro : http://pro.rajaongkir.com/api |
| 11 | 11 | | |
| 12 | 12 | */ |
| 13 | - 'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE','starter'), |
|
| 13 | + 'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'), |
|
| 14 | 14 | /* |
| 15 | 15 | |-------------------------------------------------------------------------- |
| 16 | 16 | | API key |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | | |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | - 'api_key' => env('RAJAONGKIR_API_KEY','your-api-key'), |
|
| 22 | + 'api_key' => env('RAJAONGKIR_API_KEY', 'your-api-key'), |
|
| 23 | 23 | /* |
| 24 | 24 | |-------------------------------------------------------------------------- |
| 25 | 25 | | For Caching |
@@ -8,67 +8,67 @@ discard block |
||
| 8 | 8 | use Irfa\RajaOngkir\Caching\ROCache; |
| 9 | 9 | use Exception; |
| 10 | 10 | |
| 11 | -class Ongkir extends Api{ |
|
| 11 | +class Ongkir extends Api { |
|
| 12 | 12 | |
| 13 | 13 | private static $arr; |
| 14 | 14 | private static $return; |
| 15 | 15 | |
| 16 | - public static function find($arr){ |
|
| 17 | - if(is_array($arr)){ |
|
| 16 | + public static function find($arr) { |
|
| 17 | + if (is_array($arr)) { |
|
| 18 | 18 | self::$arr = $arr; |
| 19 | 19 | return new static(); |
| 20 | - } else{ |
|
| 20 | + } else { |
|
| 21 | 21 | throw new Exception("Parameter must be an array."); |
| 22 | 22 | return false; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | } |
| 26 | - public static function get(){ |
|
| 27 | - if(empty(self::$return)){ |
|
| 26 | + public static function get() { |
|
| 27 | + if (empty(self::$return)) { |
|
| 28 | 28 | throw new Exception("Data is not defined."); |
| 29 | 29 | return false; |
| 30 | 30 | }; |
| 31 | 31 | return self::$return; |
| 32 | 32 | } |
| 33 | - public static function cachingProvince(){ |
|
| 33 | + public static function cachingProvince() { |
|
| 34 | 34 | self::cacheProvince(); |
| 35 | 35 | } |
| 36 | - public static function cachingCity(){ |
|
| 36 | + public static function cachingCity() { |
|
| 37 | 37 | self::cacheCity(); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public static function costDetails(){ |
|
| 40 | + public static function costDetails() { |
|
| 41 | 41 | self::$return = self::get_cost_details(self::$arr); |
| 42 | 42 | return new static(); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public static function courier(){ |
|
| 45 | + public static function courier() { |
|
| 46 | 46 | self::$return = self::get_courier(self::$arr); |
| 47 | 47 | return new static(); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public static function province(){ |
|
| 51 | - if(function_exists('config') AND function_exists('app')){ |
|
| 50 | + public static function province() { |
|
| 51 | + if (function_exists('config') AND function_exists('app')) { |
|
| 52 | 52 | $cache_type = strtolower(config('irfa.rajaongkir.cache_type')); |
| 53 | - if($cache_type == 'database'){ |
|
| 54 | - if(ROCache::checkProv()){ |
|
| 55 | - if(count(ROCache::getProv(self::$arr)) > 0){ |
|
| 53 | + if ($cache_type == 'database') { |
|
| 54 | + if (ROCache::checkProv()) { |
|
| 55 | + if (count(ROCache::getProv(self::$arr)) > 0) { |
|
| 56 | 56 | $ret = ROCache::getProv(self::$arr); |
| 57 | - } else{ |
|
| 57 | + } else { |
|
| 58 | 58 | $ret = self::get_province(self::$arr); |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | - } elseif($cache_type == 'file'){ |
|
| 62 | - $ret = ROCache::cacheFile(config('irfa.rajaongkir.province_table'),self::$arr); |
|
| 63 | - if($ret == null){ |
|
| 61 | + } elseif ($cache_type == 'file') { |
|
| 62 | + $ret = ROCache::cacheFile(config('irfa.rajaongkir.province_table'), self::$arr); |
|
| 63 | + if ($ret == null) { |
|
| 64 | 64 | throw new Exception("Cache is empty."); |
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - } else{ |
|
| 68 | + } else { |
|
| 69 | 69 | $ret = self::get_province(self::$arr); |
| 70 | 70 | } |
| 71 | - } else{ |
|
| 71 | + } else { |
|
| 72 | 72 | $ret = self::get_province(self::$arr); |
| 73 | 73 | } |
| 74 | 74 | self::$return = $ret; |
@@ -76,27 +76,27 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public static function city(){ |
|
| 80 | - if(function_exists('config') AND function_exists('app')){ |
|
| 79 | + public static function city() { |
|
| 80 | + if (function_exists('config') AND function_exists('app')) { |
|
| 81 | 81 | $cache_type = strtolower(config('irfa.rajaongkir.cache_type')); |
| 82 | - if($cache_type == 'database'){ |
|
| 83 | - if(ROCache::checkCity()){ |
|
| 84 | - if(count(ROCache::getCity(self::$arr)) > 0){ |
|
| 82 | + if ($cache_type == 'database') { |
|
| 83 | + if (ROCache::checkCity()) { |
|
| 84 | + if (count(ROCache::getCity(self::$arr)) > 0) { |
|
| 85 | 85 | $ret = ROCache::getCity(self::$arr); |
| 86 | - } else{ |
|
| 86 | + } else { |
|
| 87 | 87 | $ret = self::get_city(self::$arr); |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | - } elseif($cache_type == 'file'){ |
|
| 91 | - $ret = ROCache::cacheFile(config('irfa.rajaongkir.city_table'),self::$arr); |
|
| 92 | - if($ret == null){ |
|
| 90 | + } elseif ($cache_type == 'file') { |
|
| 91 | + $ret = ROCache::cacheFile(config('irfa.rajaongkir.city_table'), self::$arr); |
|
| 92 | + if ($ret == null) { |
|
| 93 | 93 | throw new Exception("Cache is empty. Try php artisan raja-ongkir:cache"); |
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | - } else{ |
|
| 96 | + } else { |
|
| 97 | 97 | $ret = self::get_city(self::$arr); |
| 98 | 98 | } |
| 99 | - } else{ |
|
| 99 | + } else { |
|
| 100 | 100 | $ret = self::get_city(self::$arr); |
| 101 | 101 | } |
| 102 | 102 | self::$return = $ret; |