@@ -12,146 +12,146 @@  | 
                                                    ||
| 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 cachingCity()  | 
                                                        |
| 54 | -    { | 
                                                        |
| 55 | - self::cacheCity();  | 
                                                        |
| 56 | - }  | 
                                                        |
| 57 | -  | 
                                                        |
| 58 | - public static function costDetails()  | 
                                                        |
| 59 | -    { | 
                                                        |
| 60 | - self::$return = self::get_cost_details(self::$arr);  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | - return new static();  | 
                                                        |
| 63 | - }  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | - public static function courier()  | 
                                                        |
| 66 | -    { | 
                                                        |
| 67 | - self::$return = self::get_courier(self::$arr);  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | - return new static();  | 
                                                        |
| 70 | - }  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - public static function province()  | 
                                                        |
| 73 | -    { | 
                                                        |
| 74 | - $ret = self::provinceData();  | 
                                                        |
| 75 | - self::$return = $ret;  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - return new static();  | 
                                                        |
| 78 | - }  | 
                                                        |
| 79 | -  | 
                                                        |
| 80 | - public static function city()  | 
                                                        |
| 81 | -    { | 
                                                        |
| 82 | - $ret = self::cityData();  | 
                                                        |
| 83 | - self::$return = $ret;  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | - return new static();  | 
                                                        |
| 86 | - }  | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - private static function setupConfig()  | 
                                                        |
| 89 | -    { | 
                                                        |
| 90 | -        self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type')); | 
                                                        |
| 91 | -        self::$province = config('irfa.rajaongkir.province_table'); | 
                                                        |
| 92 | -        self::$city = config('irfa.rajaongkir.city_table'); | 
                                                        |
| 93 | - }  | 
                                                        |
| 94 | -  | 
                                                        |
| 95 | - private static function provinceData()  | 
                                                        |
| 96 | -    { | 
                                                        |
| 97 | -        if (function_exists('config') and function_exists('app')) { | 
                                                        |
| 98 | - self::setupConfig();  | 
                                                        |
| 99 | - $cache_type = self::$cacheType;  | 
                                                        |
| 100 | -            if ($cache_type == 'database') { | 
                                                        |
| 101 | -                if (ROCache::checkProv()) { | 
                                                        |
| 102 | -                    if (count(ROCache::getProv(self::$arr)) > 0) { | 
                                                        |
| 103 | - $ret = ROCache::getProv(self::$arr);  | 
                                                        |
| 104 | -                    } else { | 
                                                        |
| 105 | - $ret = self::get_province(self::$arr);  | 
                                                        |
| 106 | - }  | 
                                                        |
| 107 | - }  | 
                                                        |
| 108 | -            } elseif ($cache_type == 'file') { | 
                                                        |
| 109 | - $ret = ROCache::cacheFile(self::$province, self::$arr);  | 
                                                        |
| 110 | -                if ($ret == null) { | 
                                                        |
| 111 | - self::exceptionCache();  | 
                                                        |
| 112 | - }  | 
                                                        |
| 113 | -            } else { | 
                                                        |
| 114 | - $ret = self::get_province(self::$arr);  | 
                                                        |
| 115 | - }  | 
                                                        |
| 116 | -        } else { | 
                                                        |
| 117 | - $ret = self::get_province(self::$arr);  | 
                                                        |
| 118 | - }  | 
                                                        |
| 119 | -  | 
                                                        |
| 120 | - return $ret;  | 
                                                        |
| 121 | - }  | 
                                                        |
| 122 | -  | 
                                                        |
| 123 | - private static function cityData()  | 
                                                        |
| 124 | -    { | 
                                                        |
| 125 | -        if (function_exists('config') and function_exists('app')) { | 
                                                        |
| 126 | - self::setupConfig();  | 
                                                        |
| 127 | - $cache_type = self::$cacheType;  | 
                                                        |
| 128 | -            if ($cache_type == 'database') { | 
                                                        |
| 129 | -                if (ROCache::checkCity()) { | 
                                                        |
| 130 | -                    if (count(ROCache::getCity(self::$arr)) > 0) { | 
                                                        |
| 131 | - $ret = ROCache::getCity(self::$arr);  | 
                                                        |
| 132 | -                    } else { | 
                                                        |
| 133 | - $ret = self::get_city(self::$arr);  | 
                                                        |
| 134 | - }  | 
                                                        |
| 135 | - }  | 
                                                        |
| 136 | -            } elseif ($cache_type == 'file') { | 
                                                        |
| 137 | - $ret = ROCache::cacheFile(self::$city, self::$arr);  | 
                                                        |
| 138 | -                if ($ret == null) { | 
                                                        |
| 139 | - self::exceptionCache();  | 
                                                        |
| 140 | - }  | 
                                                        |
| 141 | -            } else { | 
                                                        |
| 142 | - $ret = self::get_city(self::$arr);  | 
                                                        |
| 143 | - }  | 
                                                        |
| 144 | -        } else { | 
                                                        |
| 145 | - $ret = self::get_city(self::$arr);  | 
                                                        |
| 146 | - }  | 
                                                        |
| 147 | -  | 
                                                        |
| 148 | - return $ret;  | 
                                                        |
| 149 | - }  | 
                                                        |
| 150 | -  | 
                                                        |
| 151 | - private static function exceptionCache()  | 
                                                        |
| 152 | -    { | 
                                                        |
| 153 | -        throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache'); | 
                                                        |
| 154 | -  | 
                                                        |
| 155 | - return false;  | 
                                                        |
| 156 | - }  | 
                                                        |
| 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 cachingCity()  | 
                                                        |
| 54 | +	{ | 
                                                        |
| 55 | + self::cacheCity();  | 
                                                        |
| 56 | + }  | 
                                                        |
| 57 | +  | 
                                                        |
| 58 | + public static function costDetails()  | 
                                                        |
| 59 | +	{ | 
                                                        |
| 60 | + self::$return = self::get_cost_details(self::$arr);  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | + return new static();  | 
                                                        |
| 63 | + }  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | + public static function courier()  | 
                                                        |
| 66 | +	{ | 
                                                        |
| 67 | + self::$return = self::get_courier(self::$arr);  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | + return new static();  | 
                                                        |
| 70 | + }  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + public static function province()  | 
                                                        |
| 73 | +	{ | 
                                                        |
| 74 | + $ret = self::provinceData();  | 
                                                        |
| 75 | + self::$return = $ret;  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + return new static();  | 
                                                        |
| 78 | + }  | 
                                                        |
| 79 | +  | 
                                                        |
| 80 | + public static function city()  | 
                                                        |
| 81 | +	{ | 
                                                        |
| 82 | + $ret = self::cityData();  | 
                                                        |
| 83 | + self::$return = $ret;  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | + return new static();  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + private static function setupConfig()  | 
                                                        |
| 89 | +	{ | 
                                                        |
| 90 | +		self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type')); | 
                                                        |
| 91 | +		self::$province = config('irfa.rajaongkir.province_table'); | 
                                                        |
| 92 | +		self::$city = config('irfa.rajaongkir.city_table'); | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | +  | 
                                                        |
| 95 | + private static function provinceData()  | 
                                                        |
| 96 | +	{ | 
                                                        |
| 97 | +		if (function_exists('config') and function_exists('app')) { | 
                                                        |
| 98 | + self::setupConfig();  | 
                                                        |
| 99 | + $cache_type = self::$cacheType;  | 
                                                        |
| 100 | +			if ($cache_type == 'database') { | 
                                                        |
| 101 | +				if (ROCache::checkProv()) { | 
                                                        |
| 102 | +					if (count(ROCache::getProv(self::$arr)) > 0) { | 
                                                        |
| 103 | + $ret = ROCache::getProv(self::$arr);  | 
                                                        |
| 104 | +					} else { | 
                                                        |
| 105 | + $ret = self::get_province(self::$arr);  | 
                                                        |
| 106 | + }  | 
                                                        |
| 107 | + }  | 
                                                        |
| 108 | +			} elseif ($cache_type == 'file') { | 
                                                        |
| 109 | + $ret = ROCache::cacheFile(self::$province, self::$arr);  | 
                                                        |
| 110 | +				if ($ret == null) { | 
                                                        |
| 111 | + self::exceptionCache();  | 
                                                        |
| 112 | + }  | 
                                                        |
| 113 | +			} else { | 
                                                        |
| 114 | + $ret = self::get_province(self::$arr);  | 
                                                        |
| 115 | + }  | 
                                                        |
| 116 | +		} else { | 
                                                        |
| 117 | + $ret = self::get_province(self::$arr);  | 
                                                        |
| 118 | + }  | 
                                                        |
| 119 | +  | 
                                                        |
| 120 | + return $ret;  | 
                                                        |
| 121 | + }  | 
                                                        |
| 122 | +  | 
                                                        |
| 123 | + private static function cityData()  | 
                                                        |
| 124 | +	{ | 
                                                        |
| 125 | +		if (function_exists('config') and function_exists('app')) { | 
                                                        |
| 126 | + self::setupConfig();  | 
                                                        |
| 127 | + $cache_type = self::$cacheType;  | 
                                                        |
| 128 | +			if ($cache_type == 'database') { | 
                                                        |
| 129 | +				if (ROCache::checkCity()) { | 
                                                        |
| 130 | +					if (count(ROCache::getCity(self::$arr)) > 0) { | 
                                                        |
| 131 | + $ret = ROCache::getCity(self::$arr);  | 
                                                        |
| 132 | +					} else { | 
                                                        |
| 133 | + $ret = self::get_city(self::$arr);  | 
                                                        |
| 134 | + }  | 
                                                        |
| 135 | + }  | 
                                                        |
| 136 | +			} elseif ($cache_type == 'file') { | 
                                                        |
| 137 | + $ret = ROCache::cacheFile(self::$city, self::$arr);  | 
                                                        |
| 138 | +				if ($ret == null) { | 
                                                        |
| 139 | + self::exceptionCache();  | 
                                                        |
| 140 | + }  | 
                                                        |
| 141 | +			} else { | 
                                                        |
| 142 | + $ret = self::get_city(self::$arr);  | 
                                                        |
| 143 | + }  | 
                                                        |
| 144 | +		} else { | 
                                                        |
| 145 | + $ret = self::get_city(self::$arr);  | 
                                                        |
| 146 | + }  | 
                                                        |
| 147 | +  | 
                                                        |
| 148 | + return $ret;  | 
                                                        |
| 149 | + }  | 
                                                        |
| 150 | +  | 
                                                        |
| 151 | + private static function exceptionCache()  | 
                                                        |
| 152 | +	{ | 
                                                        |
| 153 | +		throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache'); | 
                                                        |
| 154 | +  | 
                                                        |
| 155 | + return false;  | 
                                                        |
| 156 | + }  | 
                                                        |
| 157 | 157 | }  |