/** * See static method * @param Repository $repository * @throws AJXP_Exception|Exception * @return AbstractAccessDriver */ public function loadRepositoryDriverREST(&$repository) { if (isset($repository->driverInstance)) { return $repository->driverInstance; } $accessType = $repository->getAccessType(); $pServ = AJXP_PluginsService::getInstance(); $plugInstance = $pServ->getPluginByTypeName("access", $accessType); // TRIGGER BEFORE INIT META $metaSources = $repository->getOption("META_SOURCES"); if (isset($metaSources) && is_array($metaSources) && count($metaSources)) { $keys = array_keys($metaSources); foreach ($keys as $plugId) { if ($plugId == "") { continue; } $instance = $pServ->getPluginById($plugId); if (!is_object($instance)) { continue; } if (!method_exists($instance, "beforeInitMeta")) { continue; } try { $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId())); $instance->beforeInitMeta($plugInstance, $repository); } catch (Exception $e) { AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage()); $this->errors[] = $e->getMessage(); } } } // INIT MAIN DRIVER $plugInstance->init($repository); try { $plugInstance->initRepository(); } catch (Exception $e) { throw $e; } AJXP_PluginsService::deferBuildingRegistry(); $pServ->setPluginUniqueActiveForType("access", $accessType); // TRIGGER INIT META $metaSources = $repository->getOption("META_SOURCES"); if (isset($metaSources) && is_array($metaSources) && count($metaSources)) { $keys = array_keys($metaSources); foreach ($keys as $plugId) { if ($plugId == "") { continue; } $split = explode(".", $plugId); $instance = $pServ->getPluginById($plugId); if (!is_object($instance)) { continue; } try { $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId())); if (!method_exists($instance, "initMeta")) { throw new Exception("Meta Source {$plugId} does not implement the initMeta method."); } $instance->initMeta($plugInstance); } catch (Exception $e) { AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage()); $this->errors[] = $e->getMessage(); } $pServ->setPluginActive($split[0], $split[1]); } } AJXP_PluginsService::flushDeferredRegistryBuilding(); if (count($this->errors) > 0) { $e = new AJXP_Exception("Error while loading repository feature : " . implode(",", $this->errors)); throw $e; } $repository->driverInstance = $plugInstance; if (isset($_SESSION["REPO_ID"]) && $_SESSION["REPO_ID"] == $repository->getId()) { $this->configs["REPOSITORY"] = $repository; if (is_array($this->configs["REPOSITORIES"])) { $this->configs["REPOSITORIES"][$_SESSION['REPO_ID']] = $repository; } } return $plugInstance; }
/** * See static method * @param Repository|null $repository * @throws AJXP_Exception|Exception * @return AbstractAccessDriver */ private function loadRepositoryDriverInst(&$repository = null) { $rest = false; if ($repository == null) { if (isset($this->configs["ACCESS_DRIVER"]) && is_a($this->configs["ACCESS_DRIVER"], "AbstractAccessDriver")) { return $this->configs["ACCESS_DRIVER"]; } $this->switchRootDirInst(); $repository = $this->getRepositoryInst(); if ($repository == null) { throw new Exception("No active repository found for user!"); } } else { $rest = true; if (isset($repository->driverInstance)) { return $repository->driverInstance; } } /** * @var AbstractAccessDriver $plugInstance */ $accessType = $repository->getAccessType(); $pServ = AJXP_PluginsService::getInstance(); $plugInstance = $pServ->getPluginByTypeName("access", $accessType); // TRIGGER BEFORE INIT META $metaSources = $repository->getOption("META_SOURCES"); if (isset($metaSources) && is_array($metaSources) && count($metaSources)) { $keys = array_keys($metaSources); foreach ($keys as $plugId) { if ($plugId == "") { continue; } $instance = $pServ->getPluginById($plugId); if (!is_object($instance)) { continue; } if (!method_exists($instance, "beforeInitMeta")) { continue; } try { $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId())); $instance->beforeInitMeta($plugInstance, $repository); } catch (Exception $e) { AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage()); $this->errors[] = $e->getMessage(); } } } // INIT MAIN DRIVER $plugInstance->init($repository); try { $plugInstance->initRepository(); $repository->driverInstance = $plugInstance; } catch (Exception $e) { if (!$rest) { // Remove repositories from the lists if (!is_a($e, "AJXP_UserAlertException")) { $this->removeRepositoryFromCache($repository->getId()); } if (isset($_SESSION["PREVIOUS_REPO_ID"]) && $_SESSION["PREVIOUS_REPO_ID"] != $repository->getId()) { $this->switchRootDir($_SESSION["PREVIOUS_REPO_ID"]); } else { $this->switchRootDir(); } } throw $e; } AJXP_PluginsService::deferBuildingRegistry(); $pServ->setPluginUniqueActiveForType("access", $accessType); // TRIGGER INIT META $metaSources = $repository->getOption("META_SOURCES"); if (isset($metaSources) && is_array($metaSources) && count($metaSources)) { $keys = array_keys($metaSources); foreach ($keys as $plugId) { if ($plugId == "") { continue; } $split = explode(".", $plugId); $instance = $pServ->getPluginById($plugId); if (!is_object($instance)) { continue; } try { $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId())); if (!method_exists($instance, "initMeta")) { throw new Exception("Meta Source {$plugId} does not implement the initMeta method."); } $instance->initMeta($plugInstance); } catch (Exception $e) { AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage()); $this->errors[] = $e->getMessage(); } $pServ->setPluginActive($split[0], $split[1]); } } AJXP_PluginsService::flushDeferredRegistryBuilding(); if (count($this->errors) > 0) { $e = new AJXP_Exception("Error while loading repository feature : " . implode(",", $this->errors)); if (!$rest) { // Remove repositories from the lists $this->removeRepositoryFromCache($repository->getId()); if (isset($_SESSION["PREVIOUS_REPO_ID"]) && $_SESSION["PREVIOUS_REPO_ID"] != $repository->getId()) { $this->switchRootDir($_SESSION["PREVIOUS_REPO_ID"]); } else { $this->switchRootDir(); } } throw $e; } if ($rest) { $ctxId = $this->getContextRepositoryId(); if ((!empty($ctxId) || $ctxId === 0) && $ctxId == $repository->getId()) { $this->configs["REPOSITORY"] = $repository; $this->cacheRepository($ctxId, $repository); } } else { $this->configs["ACCESS_DRIVER"] = $plugInstance; } return $plugInstance; }