aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/comments/appinfo/app.php25
-rw-r--r--apps/contactsinteraction/appinfo/app.php26
-rw-r--r--apps/contactsinteraction/lib/AppInfo/Application.php13
-rw-r--r--lib/private/AppFramework/Routing/RouteConfig.php11
-rw-r--r--lib/private/Route/Router.php28
-rw-r--r--tests/lib/AppFramework/Routing/RoutingTest.php7
6 files changed, 34 insertions, 76 deletions
diff --git a/apps/comments/appinfo/app.php b/apps/comments/appinfo/app.php
deleted file mode 100644
index c12c7345d89..00000000000
--- a/apps/comments/appinfo/app.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2018, Joas Schilling <coding@schilljs.com>
- *
- * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-\OC::$server->query(\OCA\Comments\AppInfo\Application::class);
diff --git a/apps/contactsinteraction/appinfo/app.php b/apps/contactsinteraction/appinfo/app.php
deleted file mode 100644
index 7bc55c958dd..00000000000
--- a/apps/contactsinteraction/appinfo/app.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-\OC::$server->query(\OCA\ContactsInteraction\AppInfo\Application::class);
diff --git a/apps/contactsinteraction/lib/AppInfo/Application.php b/apps/contactsinteraction/lib/AppInfo/Application.php
index a3cb74f408b..8d0e2fd4e71 100644
--- a/apps/contactsinteraction/lib/AppInfo/Application.php
+++ b/apps/contactsinteraction/lib/AppInfo/Application.php
@@ -27,19 +27,22 @@ namespace OCA\ContactsInteraction\AppInfo;
use OCA\ContactsInteraction\Listeners\ContactInteractionListener;
use OCP\AppFramework\App;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Contacts\Events\ContactInteractedWithEvent;
-use OCP\EventDispatcher\IEventDispatcher;
-class Application extends App {
+class Application extends App implements IBootstrap {
public const APP_ID = 'contactsinteraction';
public function __construct() {
parent::__construct(self::APP_ID);
+ }
- $this->registerListeners($this->getContainer()->query(IEventDispatcher::class));
+ public function register(IRegistrationContext $context): void {
+ $context->registerEventListener(ContactInteractedWithEvent::class, ContactInteractionListener::class);
}
- private function registerListeners(IEventDispatcher $dispatcher): void {
- $dispatcher->addServiceListener(ContactInteractedWithEvent::class, ContactInteractionListener::class);
+ public function boot(IBootContext $context): void {
}
}
diff --git a/lib/private/AppFramework/Routing/RouteConfig.php b/lib/private/AppFramework/Routing/RouteConfig.php
index c10aafd55f7..9a74564b613 100644
--- a/lib/private/AppFramework/Routing/RouteConfig.php
+++ b/lib/private/AppFramework/Routing/RouteConfig.php
@@ -140,12 +140,9 @@ class RouteConfig {
$routeName = $routeNamePrefix . $this->appName . '.' . $controller . '.' . $action . $postfix;
- // register the route
- $handler = new RouteActionHandler($this->container, $controllerName, $actionName);
-
$router = $this->router->create($routeName, $url)
->method($verb)
- ->action($handler);
+ ->setDefault('caller', [$this->appName, $controllerName, $actionName]);
// optionally register requirements for route. This is used to
// tell the route parser how url parameters should be matched
@@ -233,9 +230,9 @@ class RouteConfig {
$routeName = $routeNamePrefix . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method);
- $this->router->create($routeName, $url)->method($verb)->action(
- new RouteActionHandler($this->container, $controllerName, $actionName)
- );
+ $this->router->create($routeName, $url)
+ ->method($verb)
+ ->setDefault('caller', [$this->appName, $controllerName, $actionName]);
}
}
}
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php
index 0e436339013..3bb29961454 100644
--- a/lib/private/Route/Router.php
+++ b/lib/private/Route/Router.php
@@ -288,7 +288,12 @@ class Router implements IRouter {
}
\OC::$server->getEventLogger()->start('run_route', 'Run route');
- if (isset($parameters['action'])) {
+ if (isset($parameters['caller'])) {
+ $caller = $parameters['caller'];
+ unset($parameters['caller']);
+ $application = $this->getApplicationClass($caller[0]);
+ \OC\AppFramework\App::main($caller[1], $caller[2], $application->getContainer(), $parameters);
+ } elseif (isset($parameters['action'])) {
$action = $parameters['action'];
if (!is_callable($action)) {
throw new \Exception('not a callable action');
@@ -394,17 +399,22 @@ class Router implements IRouter {
*/
private function setupRoutes($routes, $appName) {
if (is_array($routes)) {
- $appNameSpace = App::buildAppNamespace($appName);
+ $application = $this->getApplicationClass($appName);
+ $application->registerRoutes($this, $routes);
+ }
+ }
- $applicationClassName = $appNameSpace . '\\AppInfo\\Application';
+ private function getApplicationClass(string $appName) {
+ $appNameSpace = App::buildAppNamespace($appName);
- if (class_exists($applicationClassName)) {
- $application = \OC::$server->query($applicationClassName);
- } else {
- $application = new App($appName);
- }
+ $applicationClassName = $appNameSpace . '\\AppInfo\\Application';
- $application->registerRoutes($this, $routes);
+ if (class_exists($applicationClassName)) {
+ $application = \OC::$server->query($applicationClassName);
+ } else {
+ $application = new App($appName);
}
+
+ return $application;
}
}
diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php
index 34aaff82310..c078023e653 100644
--- a/tests/lib/AppFramework/Routing/RoutingTest.php
+++ b/tests/lib/AppFramework/Routing/RoutingTest.php
@@ -3,7 +3,6 @@
namespace Test\AppFramework\Routing;
use OC\AppFramework\DependencyInjection\DIContainer;
-use OC\AppFramework\Routing\RouteActionHandler;
use OC\AppFramework\Routing\RouteConfig;
use OC\Route\Route;
use OC\Route\Router;
@@ -420,7 +419,7 @@ class RoutingTest extends \Test\TestCase {
array $defaults=[]
) {
$route = $this->getMockBuilder(Route::class)
- ->onlyMethods(['method', 'action', 'requirements', 'defaults'])
+ ->onlyMethods(['method', 'setDefault', 'requirements', 'defaults'])
->disableOriginalConstructor()
->getMock();
$route
@@ -431,8 +430,8 @@ class RoutingTest extends \Test\TestCase {
$route
->expects($this->once())
- ->method('action')
- ->with($this->equalTo(new RouteActionHandler($container, $controllerName, $actionName)))
+ ->method('setDefault')
+ ->with('caller', ['app1', $controllerName, $actionName])
->willReturn($route);
if (count($requirements) > 0) {