mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
use MTTExtensionLoaderException while loading extensions
This commit is contained in:
parent
30e6d8c5ae
commit
b589fcbdb5
2 changed files with 12 additions and 5 deletions
|
|
@ -154,6 +154,7 @@ interface MTTExtensionSettingsInterface
|
|||
function saveSettings(array $array, ?string &$outMesssage): bool;
|
||||
}
|
||||
|
||||
class MTTExtensionLoaderException extends Exception {}
|
||||
|
||||
class MTTExtensionLoader
|
||||
{
|
||||
|
|
@ -181,20 +182,20 @@ class MTTExtensionLoader
|
|||
$instanceFunc = 'mtt_ext_'. $extNormalized. '_instance';
|
||||
|
||||
if (!function_exists($instanceFunc)) {
|
||||
throw new Exception("Failed to init extension '$ext': no '$instanceFunc' function");
|
||||
throw new MTTExtensionLoaderException("Failed to init extension '$ext': no '$instanceFunc' function");
|
||||
}
|
||||
|
||||
$instance = $instanceFunc();
|
||||
if ( ! ($instance instanceof MTTExtension) ) {
|
||||
throw new Exception("Failed to init extension '$ext': incompatible instance");
|
||||
throw new MTTExtensionLoaderException("Failed to init extension '$ext': incompatible instance");
|
||||
}
|
||||
|
||||
$className = get_class($instance);
|
||||
if (!defined("$className::bundleId")) {
|
||||
throw new Exception("Failed to load extension '$ext': missing required class constants (bundleId)");
|
||||
throw new MTTExtensionLoaderException("Failed to load extension '$ext': missing required class constants (bundleId)");
|
||||
}
|
||||
if ($instance::bundleId != $ext) {
|
||||
throw new Exception("Failed to load extension '$ext': bundleId does not conforms to extension dir");
|
||||
throw new MTTExtensionLoaderException("Failed to load extension '$ext': bundleId does not conforms to extension dir");
|
||||
}
|
||||
|
||||
Lang::instance()->loadExtensionLang($ext);
|
||||
|
|
|
|||
|
|
@ -470,9 +470,15 @@ function loadExtensions()
|
|||
try {
|
||||
MTTExtensionLoader::loadExtension($ext);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
catch (MTTExtensionLoaderException $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
catch (Exception $e) {
|
||||
if (MTT_DEBUG)
|
||||
throw $e;
|
||||
else
|
||||
error_log("Error while loading extension '$ext': ". $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue