getOption(self::OPTION_ENTRYPOINTS); $entryPoints[$id] = $e; $this->setOption(self::OPTION_ENTRYPOINTS, $entryPoints); } /** * Activate an existing entry point for a specific target * * @param string $entryId * @param string $target * @throws \common_exception_InconsistentData * @return boolean success */ public function activateEntryPoint($entryId, $target) { $success = false; $entryPoints = $this->getOption(self::OPTION_ENTRYPOINTS); if (!isset($entryPoints[$entryId])) { throw new \common_exception_InconsistentData('Unknown entrypoint ' . $entryId); } $actives = $this->hasOption($target) ? $this->getOption($target) : []; if (!in_array($entryId, $actives)) { $actives[] = $entryId; $this->setOption($target, $actives); $success = true; } return $success; } /** * Dectivate an existing entry point for a specific target * * @param string $entryId * @param string $target * @throws \common_exception_InconsistentData * @return boolean success */ public function deactivateEntryPoint($entryId, $target = self::OPTION_POSTLOGIN) { $success = false; $entryPoints = $this->getOption(self::OPTION_ENTRYPOINTS); if (!isset($entryPoints[$entryId])) { throw new \common_exception_InconsistentData('Unknown entrypoint ' . $entryId); } $actives = $this->hasOption($target) ? $this->getOption($target) : []; if (in_array($entryId, $actives)) { $actives = array_diff($actives, [$entryId]); $this->setOption($target, $actives); $success = true; } else { \common_Logger::w('Tried to desactivate inactive entry point ' . $entryId); } return $success; } /** * Add an Entrypoint and activate it if a target is specified * * @param Entrypoint $e * @param string $target */ public function addEntryPoint(Entrypoint $e, $target = null) { $entryPoints = $this->getOption(self::OPTION_ENTRYPOINTS); $entryPoints[$e->getId()] = $e; $this->setOption(self::OPTION_ENTRYPOINTS, $entryPoints); if (!is_null($target)) { $this->activateEntryPoint($e->getId(), $target); } } /** * Remove entrypoint * * @param $entryId * @throws \common_exception_InconsistentData */ public function removeEntryPoint($entryId) { $entryPoints = $this->getOption(self::OPTION_ENTRYPOINTS); if (!isset($entryPoints[$entryId])) { throw new \common_exception_InconsistentData('Unknown entrypoint ' . $entryId); } // delete entrypoint from all options entries $options = $this->getOptions(); foreach ($options as $section => $option) { $sectionIsArray = false; foreach ($option as $key => $val) { if ($key === $entryId || $val == $entryId) { unset($options[$section][$key]); } if ($val == $entryId) { $sectionIsArray = true; } } if ($sectionIsArray) { $options[$section] = array_values($options[$section]); } } $this->setOptions($options); } /** * Get all entrypoints for a designated target * * @param string $target * @return Entrypoint[] */ public function getEntryPoints($target = self::OPTION_POSTLOGIN) { $ids = $this->hasOption($target) ? $this->getOption($target) : []; $existing = $this->getOption(self::OPTION_ENTRYPOINTS); if ($target === self::OPTION_ENTRYPOINTS) { return $existing; } $entryPoints = []; foreach ($ids as $id) { $entryPoints[$id] = $existing[$id]; } return $entryPoints; } /** * Legacy function for backward compatibilitiy * * @return EntryPointService * @deprecated */ public static function getRegistry() { return ServiceManager::getServiceManager()->get(self::SERVICE_ID); } /** * Legacy function for backward compatibilitiy * * @param Entrypoint $e * @param string $target * @deprecated */ public function registerEntryPoint(Entrypoint $e) { $this->addEntryPoint($e, self::OPTION_POSTLOGIN); $this->getServiceManager()->register(self::SERVICE_ID, $this); } }