|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Repositories\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Cache\Repository as Cache; |
|
6
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests; |
|
7
|
|
|
|
|
8
|
|
|
class CacheRepository implements Repository |
|
9
|
|
|
{ |
|
10
|
|
|
use ValidatesRequests; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var \Yajra\CMS\Repositories\Extension\Repository |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $repository; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \Illuminate\Contracts\Cache\Repository |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $cache; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* CacheRepository constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param \Yajra\CMS\Repositories\Extension\Repository $repository |
|
26
|
|
|
* @param \Illuminate\Contracts\Cache\Repository $cache |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(Repository $repository, Cache $cache) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->repository = $repository; |
|
31
|
|
|
$this->cache = $cache; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Install an extension. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $type |
|
38
|
|
|
* @param array $attributes |
|
39
|
|
|
* @return \Yajra\CMS\Entities\Extension |
|
40
|
|
|
*/ |
|
41
|
|
|
public function install($type, array $attributes) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->repository->install($type, $attributes); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get all extensions. |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
50
|
|
|
*/ |
|
51
|
|
|
public function all() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->cache->rememberForever('extensions.all', function () { |
|
54
|
|
|
return $this->repository->all(); |
|
55
|
|
|
}); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Uninstall extension. |
|
60
|
|
|
* |
|
61
|
|
|
* @param int $id |
|
62
|
|
|
* @throws \Exception |
|
63
|
|
|
*/ |
|
64
|
|
|
public function uninstall($id) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->repository->uninstall($id); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Find or fail an extension. |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $id |
|
73
|
|
|
* @return \Yajra\CMS\Entities\Extension |
|
74
|
|
|
*/ |
|
75
|
|
|
public function findOrFail($id) |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->cache->rememberForever('extension.' . $id, function () use ($id){ |
|
78
|
|
|
return $this->repository->findOrFail($id); |
|
79
|
|
|
}); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Register an extension using manifest config file. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $path |
|
86
|
|
|
* @throws \Exception |
|
87
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
|
88
|
|
|
*/ |
|
89
|
|
|
public function registerManifest($path) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->repository->registerManifest($path); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Register an extension. |
|
96
|
|
|
* |
|
97
|
|
|
* @param array $attributes |
|
98
|
|
|
* @return $this |
|
99
|
|
|
* @throws \Exception |
|
100
|
|
|
*/ |
|
101
|
|
|
public function register(array $attributes) |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->repository->register($attributes); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get all registered widgets. |
|
108
|
|
|
* |
|
109
|
|
|
* @return \Illuminate\Support\Collection |
|
110
|
|
|
*/ |
|
111
|
|
|
public function allWidgets() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->cache->rememberForever('extensions.widgets', function () { |
|
114
|
|
|
return $this->repository->allWidgets(); |
|
115
|
|
|
}); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|