1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
Raja Ongkir API |
5
|
|
|
Author: Irfa Ardiansyah <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Irfa\RajaOngkir\Caching; |
9
|
|
|
|
10
|
|
|
use Illuminate\Support\Facades\Cache; |
|
|
|
|
11
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
12
|
|
|
use Illuminate\Support\Facades\Schema; |
|
|
|
|
13
|
|
|
|
14
|
|
|
class ROCache |
15
|
|
|
{ |
16
|
|
|
private static $prov; |
17
|
|
|
private static $city; |
18
|
|
|
|
19
|
|
|
public static function cacheFile($name, $find = null) |
20
|
|
|
{ |
21
|
|
|
$cache = Cache::get('ro-cache-'.$name); |
22
|
|
|
if ($find != null) { |
23
|
|
|
$cache = collect($cache)->where('province_id', $find['province_id']); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return $cache; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public static function clearCache() |
30
|
|
|
{ |
31
|
|
|
self::$prov = config('irfa.rajaongkir.province_table'); |
|
|
|
|
32
|
|
|
self::$city = config('irfa.rajaongkir.city_table'); |
33
|
|
|
$cache_type = strtolower(config('irfa.rajaongkir.cache_type')); |
34
|
|
|
if ($cache_type == 'database') { |
35
|
|
|
if (Schema::hasTable(self::$city) and Schema::hasTable(self::$prov)) { |
|
|
|
|
36
|
|
|
echo 'Clearing Cache...'.PHP_EOL; |
37
|
|
|
self::clearTable(); |
38
|
|
|
echo 'Cache Cleared.'; |
39
|
|
|
} else { |
40
|
|
|
echo 'Failed. Cache table not found.'; |
41
|
|
|
|
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
} elseif ($cache_type == 'file') { |
45
|
|
|
echo 'Clearing Cache...'.PHP_EOL; |
46
|
|
|
self::clearFile(); |
47
|
|
|
echo 'Cache Cleared.'; |
48
|
|
|
} else { |
49
|
|
|
echo 'Failed. Cache type not support.'; |
50
|
|
|
|
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
self::$prov = null; |
54
|
|
|
self::$city = null; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private static function clearTable() |
58
|
|
|
{ |
59
|
|
|
DB::table(self::$prov)->truncate(); |
60
|
|
|
DB::table(self::$city)->truncate(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private static function clearFile() |
64
|
|
|
{ |
65
|
|
|
Cache::forget('ro-cache-'.self::$city); |
66
|
|
|
Cache::forget('ro-cache-'.self::$prov); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function checkProv() |
70
|
|
|
{ |
71
|
|
|
$table = config('irfa.rajaongkir.province_table'); |
|
|
|
|
72
|
|
|
if (Schema::hasTable($table)) { |
73
|
|
|
$count = DB::table($table)->count(); |
74
|
|
|
if ($count > 0) { |
75
|
|
|
return true; |
76
|
|
|
} else { |
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
} else { |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public static function checkCity() |
85
|
|
|
{ |
86
|
|
|
$table = config('irfa.rajaongkir.city_table'); |
|
|
|
|
87
|
|
|
if (Schema::hasTable($table)) { |
88
|
|
|
$count = DB::table($table)->count(); |
89
|
|
|
if ($count > 0) { |
90
|
|
|
return true; |
91
|
|
|
} else { |
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
} else { |
95
|
|
|
return false; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function getProv($arr) |
100
|
|
|
{ |
101
|
|
|
$db = DB::table(config('irfa.rajaongkir.province_table')); |
|
|
|
|
102
|
|
|
if (!empty($arr)) { |
103
|
|
|
$db->where($arr); |
104
|
|
|
} |
105
|
|
|
$ret = $db->orderBy('province', 'DESC')->get(); |
106
|
|
|
|
107
|
|
|
return $ret; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public static function getSubdistrict($arr) |
111
|
|
|
{ |
112
|
|
|
$db = DB::table(config('irfa.rajaongkir.subdistrict_table')); |
|
|
|
|
113
|
|
|
if (!empty($arr)) { |
114
|
|
|
$db->where($arr); |
115
|
|
|
} |
116
|
|
|
$ret = $db->orderBy('subdistrict_name', 'DESC')->get(); |
117
|
|
|
|
118
|
|
|
return $ret; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public static function getCity($arr) |
122
|
|
|
{ |
123
|
|
|
$db = DB::table(config('irfa.rajaongkir.city_table')); |
|
|
|
|
124
|
|
|
if (!empty($arr)) { |
125
|
|
|
$db->where($arr); |
126
|
|
|
} |
127
|
|
|
$ret = $db->orderBy('city_name', 'ASC')->get(); |
128
|
|
|
|
129
|
|
|
return $ret; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths