Main update
This commit is contained in:
@@ -48,11 +48,16 @@ final class AppVisibility
|
||||
|
||||
return array_values(array_filter($apps, static function (array $app) use ($lookup, $mandatoryLookup): bool {
|
||||
$appId = (string) ($app['app_id'] ?? '');
|
||||
$installable = !array_key_exists('installable', $app) || (bool) $app['installable'];
|
||||
|
||||
if ($appId === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$installable) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isset($lookup[$appId]) || isset($mandatoryLookup[$appId]);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -9,11 +9,29 @@ final class WidgetRegistry
|
||||
/** @var array<int, array<string, mixed>> */
|
||||
private array $widgets;
|
||||
|
||||
public function __construct(string $configPath)
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $additionalWidgets
|
||||
*/
|
||||
public function __construct(string $configPath, array $additionalWidgets = [])
|
||||
{
|
||||
/** @var array<int, array<string, mixed>> $widgets */
|
||||
$widgets = require $configPath;
|
||||
$this->widgets = $widgets;
|
||||
$lookup = [];
|
||||
|
||||
foreach (array_merge($widgets, $additionalWidgets) as $widget) {
|
||||
if (!is_array($widget)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$widgetId = (string) ($widget['widget_id'] ?? '');
|
||||
if ($widgetId === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lookup[$widgetId] = $widget;
|
||||
}
|
||||
|
||||
$this->widgets = array_values($lookup);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,15 +43,38 @@ final class WidgetRegistry
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $widgetIds
|
||||
* @param array<int, string> $enabledAppIds
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function active(array $widgetIds): array
|
||||
public function availableForApps(array $enabledAppIds): array
|
||||
{
|
||||
$lookup = array_fill_keys($widgetIds, true);
|
||||
$enabledLookup = array_fill_keys($enabledAppIds, true);
|
||||
|
||||
return array_values(array_filter(
|
||||
$this->widgets,
|
||||
static function (array $widget) use ($enabledLookup): bool {
|
||||
$sourceAppId = trim((string) ($widget['source_app_id'] ?? ''));
|
||||
if ($sourceAppId === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isset($enabledLookup[$sourceAppId]);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $widgetIds
|
||||
* @param array<int, string> $enabledAppIds
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function active(array $widgetIds, array $enabledAppIds = []): array
|
||||
{
|
||||
$lookup = array_fill_keys($widgetIds, true);
|
||||
$available = $enabledAppIds === [] ? $this->widgets : $this->availableForApps($enabledAppIds);
|
||||
|
||||
return array_values(array_filter(
|
||||
$available,
|
||||
static fn (array $widget): bool => isset($lookup[$widget['widget_id'] ?? ''])
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user