*/ class QtiCreatorClientConfigRegistry extends ClientLibConfigRegistry { const CREATOR = "taoQtiItem/controller/creator/index"; /** * @param $name * @param $module * @param $category * @param null $position * @throws \common_exception_InvalidArgumentType */ public function registerPlugin($name, $module, $category, $position = null) { if (!is_string($name)) { throw new \common_exception_InvalidArgumentType('The plugin name must be a string!'); } if (!is_string($module)) { throw new \common_exception_InvalidArgumentType('The module path must be a string!'); } if (!is_string($category)) { throw new \common_exception_InvalidArgumentType('The category name must be a string!'); } if (!is_null($position) && !is_string($position) && !is_numeric($position)) { throw new \common_exception_InvalidArgumentType('The position must be a string or a number!'); } $config = []; $registry = self::getRegistry(); if ($registry->isRegistered(self::CREATOR)) { $config = $registry->get(self::CREATOR); } $plugins = []; if (isset($config['plugins'])) { foreach ($config['plugins'] as $plugin) { if ($plugin['module'] != $module) { $plugins[] = $plugin; } } } $plugins[] = [ 'name' => $name, 'module' => $module, 'category' => $category, 'position' => $position, ]; $config['plugins'] = array_values($plugins); $registry->set(self::CREATOR, $config); } /** * @param $name * @param $module * @param $category * @param null $position */ public function removePlugin($name, $module, $category, $position = null) { $config = []; $registry = self::getRegistry(); if ($registry->isRegistered(self::CREATOR)) { $config = $registry->get(self::CREATOR); } if (!isset($config['plugins'])) { return; } $plugins = $config['plugins']; $plugin = [ 'name' => $name, 'module' => $module, 'category' => $category, 'position' => $position, ]; $key = array_search($plugin, $plugins); if (is_numeric($key)) { unset($plugins[$key]); } $config['plugins'] = $plugins; $registry->set(self::CREATOR, $config); } /** * Quick access to the plugins * @return array the registered plugins */ public function getPlugins() { $config = []; $registry = self::getRegistry(); if ($registry->isRegistered(self::CREATOR)) { $config = $registry->get(self::CREATOR); } if (!isset($config['plugins'])) { return []; } return $config['plugins']; } }