mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +08:00
Use extension names instead of IDs when erroring on enable/disable reqs (#2563)
This commit is contained in:
parent
9ff85d661e
commit
e03504a7f2
|
@ -11,6 +11,7 @@ namespace Flarum\Extension\Exception;
|
|||
|
||||
use Exception;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
|
||||
/**
|
||||
* This exception is thrown when someone attempts to disable an extension
|
||||
|
@ -30,18 +31,6 @@ class DependentExtensionsException extends Exception
|
|||
$this->extension = $extension;
|
||||
$this->dependent_extensions = $dependent_extensions;
|
||||
|
||||
parent::__construct($extension->getId().' could not be disabled, because it is a dependency of: '.implode(', ', $this->getDependentExtensionIds()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of IDs for extensions that depend on this extension.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDependentExtensionIds()
|
||||
{
|
||||
return array_map(function (Extension $extension) {
|
||||
return $extension->getId();
|
||||
}, $this->dependent_extensions);
|
||||
parent::__construct($extension->getTitle().' could not be disabled, because it is a dependency of: '.implode(', ', ExtensionManager::pluckTitles($dependent_extensions)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Flarum\Extension\Exception;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Foundation\ErrorHandling\HandledError;
|
||||
|
||||
class DependentExtensionsExceptionHandler
|
||||
|
@ -26,8 +27,8 @@ class DependentExtensionsExceptionHandler
|
|||
{
|
||||
return [
|
||||
[
|
||||
'extension' => $e->extension->getId(),
|
||||
'extensions' => $e->getDependentExtensionIds(),
|
||||
'extension' => $e->extension->getTitle(),
|
||||
'extensions' => ExtensionManager::pluckTitles($e->dependent_extensions),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Flarum\Extension\Exception;
|
|||
|
||||
use Exception;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
|
||||
/**
|
||||
* This exception is thrown when someone attempts to enable an extension
|
||||
|
@ -30,18 +31,6 @@ class MissingDependenciesException extends Exception
|
|||
$this->extension = $extension;
|
||||
$this->missing_dependencies = $missing_dependencies;
|
||||
|
||||
parent::__construct($extension->getId().' could not be enabled, because it depends on: '.implode(', ', $this->getMissingDependencyIds()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of IDs for missing (disabled) extensions that this extension depends on.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMissingDependencyIds()
|
||||
{
|
||||
return array_map(function (Extension $extension) {
|
||||
return $extension->getId();
|
||||
}, $this->missing_dependencies);
|
||||
parent::__construct($extension->getTitle().' could not be enabled, because it depends on: '.implode(', ', ExtensionManager::pluckTitles($missing_dependencies)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Flarum\Extension\Exception;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Foundation\ErrorHandling\HandledError;
|
||||
|
||||
class MissingDependenciesExceptionHandler
|
||||
|
@ -26,8 +27,8 @@ class MissingDependenciesExceptionHandler
|
|||
{
|
||||
return [
|
||||
[
|
||||
'extension' => $e->extension->getId(),
|
||||
'extensions' => $e->getMissingDependencyIds(),
|
||||
'extension' => $e->extension->getTitle(),
|
||||
'extensions' => ExtensionManager::pluckTitles($e->missing_dependencies),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -278,6 +278,14 @@ class Extension implements Arrayable
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->composerJsonAttribute('extra.flarum-extension.title');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -114,7 +114,7 @@ class ExtensionManager
|
|||
}
|
||||
|
||||
$this->extensions = $extensions->sortBy(function ($extension, $name) {
|
||||
return $extension->composerJsonAttribute('extra.flarum-extension.title');
|
||||
return $extension->getTitle();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -369,4 +369,17 @@ class ExtensionManager
|
|||
|
||||
return isset($enabled[$extension]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the titles of the extensions passed.
|
||||
*
|
||||
* @param array $exts
|
||||
* @return string[]
|
||||
*/
|
||||
public static function pluckTitles(array $exts)
|
||||
{
|
||||
return array_map(function (Extension $extension) {
|
||||
return $extension->getTitle();
|
||||
}, $exts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ class EnableBundledExtensions implements Step
|
|||
})->filter(function (Extension $extension) {
|
||||
return in_array($extension->getId(), self::EXTENSION_WHITELIST);
|
||||
})->sortBy(function (Extension $extension) {
|
||||
return $extension->composerJsonAttribute('extra.flarum-extension.title');
|
||||
return $extension->getTitle();
|
||||
})->mapWithKeys(function (Extension $extension) {
|
||||
return [$extension->getId() => $extension];
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user