*/ private static array $failed = []; public static function registerTools(): void { foreach (self::DOMAINS as $class) { self::guard($class, 'register', static function () use ($class): void { $class::register(); }); } } /** @return list<\Llamly\Free\History\Adapter> */ public static function adapters(): array { $adapters = []; foreach (self::DOMAINS as $class) { self::guard($class, 'adapters', static function () use ($class, &$adapters): void { foreach ($class::adapters() as $adapter) { $adapters[] = $adapter; } }); } return $adapters; } /** @return array domain class => error code, for the Doctor and Sobre. */ public static function failures(): array { return self::$failed; } private static function guard(string $class, string $method, callable $run): void { try { if (!class_exists($class) || !method_exists($class, $method)) { return; } $run(); } catch (\Throwable $error) { if (!isset(self::$failed[$class])) { self::$failed[$class] = get_class($error); if (function_exists('error_log')) { error_log('[llamly] domain ' . $class . ' failed to load: ' . get_class($error) . ': ' . $error->getMessage()); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- logged once when a tool domain fails to load, so the site owner can see why tools are missing. } } } } }