registryEntryKey = $registryEntryKey; } /** * @return AbstractRegistry */ public function getRegistry(): AbstractRegistry { if (!isset($this->registry)) { $this->registry = ClientLibConfigRegistry::getRegistry(); } return $this->registry; } /** * @param AbstractRegistry $registry */ public function setRegistry(AbstractRegistry $registry): void { $this->registry = $registry; } /** * @return array */ public function getAdapters(): array { $registry = $this->getRegistry(); if ($registry->isRegistered($this->registryEntryKey)) { $config = $registry->get($this->registryEntryKey); } return $config[self::PREVIEWERS_KEY] ?? []; } /** * @param DynamicModule $module * * @return bool */ public function registerAdapter(DynamicModule $module): bool { if ($module === null || empty($module->getModule())) { return false; } $registry = $this->getRegistry(); if ($registry->isRegistered($this->registryEntryKey)) { $config = $registry->get($this->registryEntryKey); } $config[self::PREVIEWERS_KEY][$module->getModule()] = $module->toArray(); $registry->set($this->registryEntryKey, $config); return true; } /** * @param string $moduleId * * @return bool */ public function unregisterAdapter(string $moduleId): bool { $registry = $this->getRegistry(); if ($registry->isRegistered($this->registryEntryKey)) { $config = $registry->get($this->registryEntryKey); } if (isset($config[self::PREVIEWERS_KEY][$moduleId])) { unset($config[self::PREVIEWERS_KEY][$moduleId]); $registry->set($this->registryEntryKey, $config); return true; } return false; } /** * @return array */ public function getPlugins(): array { $registry = $this->getRegistry(); if ($registry->isRegistered($this->registryEntryKey)) { $config = $registry->get($this->registryEntryKey); } return $config[self::PLUGINS_KEY] ?? []; } /** * @param DynamicModule $module * * @return bool */ public function registerPlugin(DynamicModule $module): bool { if ($module === null || empty($module->getModule())) { return false; } $this->unregisterPlugin($module->getModule()); $registry = $this->getRegistry(); if ($registry->isRegistered($this->registryEntryKey)) { $config = $registry->get($this->registryEntryKey); } $config[self::PLUGINS_KEY][] = $module->toArray(); $registry->set($this->registryEntryKey, $config); return true; } /** * @param string $module * * @return bool */ public function unregisterPlugin(string $module): bool { $registry = $this->getRegistry(); if ($registry->isRegistered($this->registryEntryKey)) { $config = $registry->get($this->registryEntryKey); } $result = false; if (isset($config[self::PLUGINS_KEY])) { $config[self::PLUGINS_KEY] = array_filter( $config[self::PLUGINS_KEY], static function (array $plugin) use ($module, &$result): bool { $result = $plugin['module'] === $module; return !$result; } ); $registry->set($this->registryEntryKey, $config); } return $result; } }