1
|
|
|
<?php namespace Arcanedev\GeoIP\Console; |
2
|
|
|
|
3
|
|
|
use Arcanedev\GeoIP\Contracts\GeoIPCache; |
4
|
|
|
use Arcanedev\Support\Bases\Command; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class ClearCommand |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\GeoIP\Console |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class ClearCommand extends Command |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Properties |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command name. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $name = 'geoip:clear'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The console command description. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $description = 'Clear the GeoIP cached data.'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Supported cache stores. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $supported = ['apc', 'array', 'memcached', 'redis']; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The GeoIP Cache instance. |
42
|
|
|
* |
43
|
|
|
* @var \Arcanedev\GeoIP\Contracts\GeoIPCache |
44
|
|
|
*/ |
45
|
|
|
private $cache; |
46
|
|
|
|
47
|
|
|
/* ----------------------------------------------------------------- |
48
|
|
|
| Constructor |
49
|
|
|
| ----------------------------------------------------------------- |
50
|
|
|
*/ |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* ClearCommand constructor. |
54
|
|
|
* |
55
|
|
|
* @param \Arcanedev\GeoIP\Contracts\GeoIPCache $cache |
56
|
|
|
*/ |
57
|
|
|
public function __construct(GeoIPCache $cache) |
58
|
|
|
{ |
59
|
|
|
parent::__construct(); |
60
|
|
|
|
61
|
|
|
$this->cache = $cache; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/* ----------------------------------------------------------------- |
65
|
|
|
| Main Methods |
66
|
|
|
| ----------------------------------------------------------------- |
67
|
|
|
*/ |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Execute the console command. |
71
|
|
|
*/ |
72
|
|
|
public function handle() |
73
|
|
|
{ |
74
|
|
|
if ($this->isSupported($default = $this->getDefaultCache())) { |
75
|
|
|
$this->comment('Clearing the cache data...'); |
76
|
|
|
|
77
|
|
|
$this->cache->flush(); |
78
|
|
|
|
79
|
|
|
$this->info("Cache clearing was completed!"); |
80
|
|
|
} |
81
|
|
|
else |
82
|
|
|
$this->error("Default cache system [$default] does not support tags"); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/* ----------------------------------------------------------------- |
86
|
|
|
| Other Methods |
87
|
|
|
| ----------------------------------------------------------------- |
88
|
|
|
*/ |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the config repository. |
92
|
|
|
* |
93
|
|
|
* @return \Illuminate\Contracts\Config\Repository |
94
|
|
|
*/ |
95
|
|
|
protected function config() |
96
|
|
|
{ |
97
|
|
|
return $this->laravel['config']; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the default cache. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
protected function getDefaultCache() |
106
|
|
|
{ |
107
|
|
|
return $this->config()->get('cache.default'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Is cache flushing supported. |
112
|
|
|
* |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
protected function isSupported($default) |
116
|
|
|
{ |
117
|
|
|
return in_array($default, $this->supported) && |
118
|
|
|
! empty($this->config()->get('geoip.cache.tags', [])); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|