+ try {
+ // Check if the HTTP method is OPTIONS and return the special Options Module with the possible HTTP methods
+ if ($this->args->getMethod() === static::OPTIONS) {
+ $this->moduleClass = Options::class;
+ $this->parameters[] = ['AllowedMethods' => $dispatcher->getOptions($cmd)];
+ } else {
+ $routeInfo = $dispatcher->dispatch($this->args->getMethod(), $cmd);
+ if ($routeInfo[0] === Dispatcher::FOUND) {
+ $this->moduleClass = $routeInfo[1];
+ $this->parameters[] = $routeInfo[2];
+ } else if ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
+ throw new HTTPException\MethodNotAllowedException($this->l10n->t('Method not allowed for this module. Allowed method(s): %s', implode(', ', $routeInfo[1])));
+ } else {
+ throw new HTTPException\NotFoundException($this->l10n->t('Page not found.'));
+ }
+ }
+ } catch (MethodNotAllowedException $e) {
+ $this->moduleClass = MethodNotAllowed::class;
+ } catch (NotFoundException $e) {
+ $moduleName = $this->args->getModuleName();
+ // Then we try addon-provided modules that we wrap in the LegacyModule class
+ if (Addon::isEnabled($moduleName) && file_exists("addon/{$moduleName}/{$moduleName}.php")) {
+ //Check if module is an app and if public access to apps is allowed or not
+ $privateapps = $this->config->get('config', 'private_addons', false);
+ if (!$this->isLocalUser && Hook::isAddonApp($moduleName) && $privateapps) {
+ throw new MethodNotAllowedException($this->l10n->t("You must be logged in to use addons. "));
+ } else {
+ include_once "addon/{$moduleName}/{$moduleName}.php";
+ if (function_exists($moduleName . '_module')) {
+ $this->parameters[] = "addon/{$moduleName}/{$moduleName}.php";
+ $this->moduleClass = LegacyModule::class;
+ }
+ }
+ }