1
|
|
|
<?php namespace Mascame\Artificer\Controllers; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Str; |
4
|
|
|
use Mascame\Artificer\Artificer; |
5
|
|
|
use View; |
6
|
|
|
|
7
|
|
|
class ExtensionController extends BaseController |
8
|
|
|
{ |
9
|
|
|
const ACTION_INSTALL = 'install'; |
10
|
|
|
const ACTION_UNINSTALL = 'uninstall'; |
11
|
|
|
|
12
|
|
|
const TYPE_PLUGINS = 'plugins'; |
13
|
|
|
const TYPE_WIDGETS = 'widgets'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var |
17
|
|
|
*/ |
18
|
|
|
protected $type; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return mixed |
22
|
|
|
*/ |
23
|
|
|
protected function getManager() { |
24
|
|
|
if ($this->getType() == 'plugins') { |
25
|
|
|
return Artificer::pluginManager(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return Artificer::widgetManager(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
protected function getType() { |
35
|
|
|
if ($this->type) return $this->type; |
36
|
|
|
|
37
|
|
|
return Str::startsWith(\Route::currentRouteName(), 'admin.plugins') ? self::TYPE_PLUGINS : self::TYPE_WIDGETS; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function extensions() |
41
|
|
|
{ |
42
|
|
|
return View::make($this->getView('extensions')) |
43
|
|
|
// Both plugins and widgets use the same manager |
44
|
|
|
->with('packages', Artificer::pluginManager()->getPackages() |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $extension |
50
|
|
|
* @return \Illuminate\Http\RedirectResponse |
51
|
|
|
*/ |
52
|
|
|
public function install($extension) |
53
|
|
|
{ |
54
|
|
|
return $this->doAction($extension, self::ACTION_INSTALL); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $extension |
59
|
|
|
* @return \Illuminate\Http\RedirectResponse |
60
|
|
|
*/ |
61
|
|
|
public function uninstall($extension) |
62
|
|
|
{ |
63
|
|
|
return $this->doAction($extension, self::ACTION_UNINSTALL); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $extension |
68
|
|
|
* @param $action |
69
|
|
|
* @return \Illuminate\Http\RedirectResponse |
70
|
|
|
* @throws \Exception |
71
|
|
|
*/ |
72
|
|
|
protected function doAction($extension, $action) |
73
|
|
|
{ |
74
|
|
|
$extension = $this->getExtensionSlug($extension); |
75
|
|
|
|
76
|
|
|
if ($action == self::ACTION_UNINSTALL && Artificer::isCoreExtension($extension->package)) { |
77
|
|
|
throw new \Exception('Core extensions can not be uninstalled'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->getManager()->installer()->$action($extension->namespace); |
81
|
|
|
|
82
|
|
|
return \Redirect::back(); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $plugin |
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
|
|
protected function getExtensionSlug($plugin) { |
90
|
|
|
return $this->getManager()->getFromSlug($plugin); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.