module_title = _t('svc', 'Services'); } /** * Register service manager * @param string $key unique key * @param string $className class name * @return bool */ public function registerServiceManager(string $key, string $className): bool { if (empty($key) || array_key_exists($key, $this->serviceManagers)) { return false; } $this->serviceManagers[$key] = $className; $this->app->singleton($className); return true; } /** * Init registered service manager by key * @param string $key * @return ServiceManager|null */ public function getServiceManager(string $key): ?ServiceManager { if (! array_key_exists($key, $this->serviceManagers)) { return null; } return $this->app->make($this->serviceManagers[$key]); } /** * Install registered service * @param string $manager key * @param string $service class name * @param array $opts * @return bool */ public function installService(string $manager, string $service, array $opts = []): bool { $manager = $this->getServiceManager($manager); if (! $manager) { return false; } return $manager->installService($service, $opts); } /** * Activate list of services * @param array $list */ public function activateServices(array $list) { if (empty($list)) { return; } foreach ($list as $v) { if (! isset($v['group'])) { continue; } $manager = $this->getServiceManager($v['group']); if (! $manager) { continue; } if (! isset($v['key'])) { continue; } $service = $manager->getService($v['key']); if (! $service) { continue; } $service->setActivationSettings($v['item'] ?? 0, $v['user'] ?? 0, $v); $service->activate(); } } /** * Get titles list of services * @param array $list * @return array */ public function servicesTitles(array $list) { $result = []; foreach ($list as $v) { if (! isset($v['group'])) { continue; } $manager = $this->getServiceManager($v['group']); if (! $manager) { continue; } if (! isset($v['key'])) { continue; } $service = $manager->getService($v['key']); if (! $service) { continue; } if ($service->isPack()) { $result[] = _t('svc', 'Service package "[title]"', ['title' => $service->getTitle()]); } else { $result[] = _t('svc', 'Service "[title]"', ['title' => $service->getTitle()]); } } return $result; } public function getSvcTypes() { return [ static::TYPE_SERVICE => [ 'id' => static::TYPE_SERVICE, 'title_select' => _t('svc', 'Service'), 'title_list' => _t('svc', 'Services'), ], ]; } }