Update the parameter of PluginManager::getUnsatisfiedRequirements method

This commit is contained in:
printempw 2018-06-29 18:14:55 +08:00
parent 967e1642d3
commit 4da044146f
3 changed files with 13 additions and 11 deletions

View File

@ -47,10 +47,10 @@ class PluginController extends Controller
switch ($request->get('action')) { switch ($request->get('action')) {
case 'enable': case 'enable':
if (! $plugins->isRequirementsSatisfied($name)) { if (! $plugins->isRequirementsSatisfied($plugin)) {
$msg = ''; $msg = '';
foreach ($plugins->getUnsatisfiedRequirements($name) as $name => $detail) { foreach ($plugins->getUnsatisfiedRequirements($plugin) as $name => $detail) {
if (! $detail['version']) { if (! $detail['version']) {
$msg .= '<li>'.trans('admin.plugins.operations.unsatisfied.disabled', [ $msg .= '<li>'.trans('admin.plugins.operations.unsatisfied.disabled', [
'name' => "<code>$name</code>" 'name' => "<code>$name</code>"
@ -123,9 +123,9 @@ class PluginController extends Controller
$plugins = app('plugins'); $plugins = app('plugins');
return [ return [
'isRequirementsSatisfied' => $plugins->isRequirementsSatisfied($plugin->name), 'isRequirementsSatisfied' => $plugins->isRequirementsSatisfied($plugin),
'requirements' => $plugin->getRequirements(), 'requirements' => $plugin->getRequirements(),
'unsatisfiedRequirements' => $plugins->getUnsatisfiedRequirements($plugin->name) 'unsatisfiedRequirements' => $plugins->getUnsatisfiedRequirements($plugin)
]; ];
} }
} }

View File

@ -58,7 +58,7 @@ class PluginServiceProvider extends ServiceProvider
protected function disableRequirementsUnsatisfiedPlugins(PluginManager $manager) protected function disableRequirementsUnsatisfiedPlugins(PluginManager $manager)
{ {
foreach ($manager->getEnabledPlugins() as $plugin) { foreach ($manager->getEnabledPlugins() as $plugin) {
if (! $manager->isRequirementsSatisfied($plugin->name)) { if (! $manager->isRequirementsSatisfied($plugin)) {
$manager->disable($plugin->name); $manager->disable($plugin->name);
} }
} }

View File

@ -277,12 +277,14 @@ class PluginManager
/** /**
* Get the unsatisfied requirements of plugin. * Get the unsatisfied requirements of plugin.
* *
* @param string $pluginName * @param string|Plugin $plugin
* @return array * @return array
*/ */
public function getUnsatisfiedRequirements($pluginName) public function getUnsatisfiedRequirements($plugin)
{ {
$plugin = $this->getPlugin($pluginName); if (! $plugin instanceof Plugin) {
$plugin = $this->getPlugin($plugin);
}
if (! $plugin) { if (! $plugin) {
throw new \InvalidArgumentException('Plugin with given name does not exist.'); throw new \InvalidArgumentException('Plugin with given name does not exist.');
@ -332,12 +334,12 @@ class PluginManager
/** /**
* Whether the plugin's requirements are satisfied. * Whether the plugin's requirements are satisfied.
* *
* @param string $pluginName * @param string|Plugin $plugin
* @return bool * @return bool
*/ */
public function isRequirementsSatisfied($pluginName) public function isRequirementsSatisfied($plugin)
{ {
return empty($this->getUnsatisfiedRequirements($pluginName)); return empty($this->getUnsatisfiedRequirements($plugin));
} }
/** /**