mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
store extension meta in extension.json
This commit is contained in:
parent
8e61b1c681
commit
8fcab7b89b
3 changed files with 26 additions and 12 deletions
|
|
@ -65,7 +65,7 @@ foreach (MTTExtensionLoader::loadedExtensions() as $instance) {
|
|||
if ($instance instanceof MTTHttpApiExtender) {
|
||||
$newRoutes = $instance->extendHttpApi();
|
||||
foreach ($newRoutes as $endpoint => $methods) {
|
||||
$endpoint = '/ext/'. $instance::codename. $endpoint;
|
||||
$endpoint = '/ext/'. $instance::bundleId. $endpoint;
|
||||
foreach ($methods as $k => &$v) {
|
||||
$v[2] = true; // Mark extension method
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ abstract class ApiController
|
|||
|
||||
abstract class MTTExtension
|
||||
{
|
||||
const codename = '';
|
||||
const bundleId = '';
|
||||
const title = '';
|
||||
abstract function init();
|
||||
}
|
||||
|
|
@ -120,11 +120,11 @@ class MTTExtensionLoader
|
|||
}
|
||||
|
||||
$className = get_class($instance);
|
||||
if (!defined("$className::codename") || !defined("$className::title")) {
|
||||
throw new Exception("Failed to register extension '$ext': require class constants (codename, title)");
|
||||
if (!defined("$className::bundleId") || !defined("$className::title")) {
|
||||
throw new Exception("Failed to register extension '$ext': require class constants (bundleId, title)");
|
||||
}
|
||||
if ($instance::codename != $ext) {
|
||||
throw new Exception("Extension '$ext' codename does not conforms to extension dir");
|
||||
if ($instance::bundleId != $ext) {
|
||||
throw new Exception("Extension '$ext' bundleId does not conforms to extension dir");
|
||||
}
|
||||
|
||||
$instance->init();
|
||||
|
|
@ -151,10 +151,23 @@ class MTTExtensionLoader
|
|||
$a = [];
|
||||
$files = array_diff(scandir(MTT_EXT) ?? [], ['.', '..']);
|
||||
foreach ($files as $ext) {
|
||||
if ( !is_dir(MTT_EXT. $ext) || !file_exists(MTT_EXT. $ext. '/loader.php') ) {
|
||||
if ( !is_dir(MTT_EXT. $ext)
|
||||
|| !file_exists(MTT_EXT. $ext. '/loader.php')
|
||||
|| !file_exists(MTT_EXT. $ext. '/extension.json') ) {
|
||||
continue;
|
||||
}
|
||||
$a[] = $ext;
|
||||
$jsonData = file_get_contents(MTT_EXT. $ext. '/extension.json');
|
||||
if ($jsonData === false) {
|
||||
continue;
|
||||
}
|
||||
$meta = json_decode($jsonData, true);
|
||||
if (!is_array($meta) || !isset($meta['bundleId']) || !isset($meta['title']) || !isset($meta['description'])) {
|
||||
continue;
|
||||
}
|
||||
if (!is_string($meta['bundleId']) || !is_string($meta['title']) || !is_string($meta['description'])) {
|
||||
continue;
|
||||
}
|
||||
$a[$ext] = $meta;
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ else if (isset($_POST['activate']))
|
|||
$activate = (int)_post('activate');
|
||||
$ext = _post('ext');
|
||||
|
||||
$exts = MTTExtensionLoader::bundles();
|
||||
$extBundles = MTTExtensionLoader::bundles();
|
||||
$exts = array_keys($extBundles);
|
||||
$a = Config::get('extensions');
|
||||
if (!is_array($a)) $a = [];
|
||||
|
||||
|
|
@ -189,11 +190,11 @@ function timezoneIdentifiers()
|
|||
|
||||
function listExtensions()
|
||||
{
|
||||
$exts = MTTExtensionLoader::bundles();
|
||||
$extBundles = MTTExtensionLoader::bundles();
|
||||
$activatedExts = Config::get('extensions');
|
||||
if (!is_array($activatedExts)) $activatedExts = [];
|
||||
foreach ($exts as $ext) {
|
||||
$out = "$ext ";
|
||||
foreach ($extBundles as $ext => $meta) {
|
||||
$out = htmlspecialchars($meta['title']). ' ';
|
||||
if (in_array($ext, $activatedExts)) {
|
||||
$out .= "<a href='#' data-settings-link='ext-deactivate' data-ext='". htmlspecialchars($ext). "'>". __('set_deactivate', true). '</a>';
|
||||
$instance = MTTExtensionLoader::extensionInstance($ext);
|
||||
|
|
|
|||
Loading…
Reference in a new issue