Merge pull request #21643 from nextcloud/enh/no_routeactionhadler_inits
Do not create a RouteActionHandler object for each route
This commit is contained in:
commit
7a92113fec
|
@ -140,12 +140,9 @@ class RouteConfig {
|
||||||
|
|
||||||
$routeName = $routeNamePrefix . $this->appName . '.' . $controller . '.' . $action . $postfix;
|
$routeName = $routeNamePrefix . $this->appName . '.' . $controller . '.' . $action . $postfix;
|
||||||
|
|
||||||
// register the route
|
|
||||||
$handler = new RouteActionHandler($this->container, $controllerName, $actionName);
|
|
||||||
|
|
||||||
$router = $this->router->create($routeName, $url)
|
$router = $this->router->create($routeName, $url)
|
||||||
->method($verb)
|
->method($verb)
|
||||||
->action($handler);
|
->setDefault('caller', [$this->appName, $controllerName, $actionName]);
|
||||||
|
|
||||||
// optionally register requirements for route. This is used to
|
// optionally register requirements for route. This is used to
|
||||||
// tell the route parser how url parameters should be matched
|
// tell the route parser how url parameters should be matched
|
||||||
|
@ -233,9 +230,9 @@ class RouteConfig {
|
||||||
|
|
||||||
$routeName = $routeNamePrefix . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method);
|
$routeName = $routeNamePrefix . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method);
|
||||||
|
|
||||||
$this->router->create($routeName, $url)->method($verb)->action(
|
$this->router->create($routeName, $url)
|
||||||
new RouteActionHandler($this->container, $controllerName, $actionName)
|
->method($verb)
|
||||||
);
|
->setDefault('caller', [$this->appName, $controllerName, $actionName]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,12 @@ class Router implements IRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
\OC::$server->getEventLogger()->start('run_route', 'Run route');
|
\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'];
|
$action = $parameters['action'];
|
||||||
if (!is_callable($action)) {
|
if (!is_callable($action)) {
|
||||||
throw new \Exception('not a callable action');
|
throw new \Exception('not a callable action');
|
||||||
|
@ -394,6 +399,12 @@ class Router implements IRouter {
|
||||||
*/
|
*/
|
||||||
private function setupRoutes($routes, $appName) {
|
private function setupRoutes($routes, $appName) {
|
||||||
if (is_array($routes)) {
|
if (is_array($routes)) {
|
||||||
|
$application = $this->getApplicationClass($appName);
|
||||||
|
$application->registerRoutes($this, $routes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getApplicationClass(string $appName) {
|
||||||
$appNameSpace = App::buildAppNamespace($appName);
|
$appNameSpace = App::buildAppNamespace($appName);
|
||||||
|
|
||||||
$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
|
$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
|
||||||
|
@ -404,7 +415,6 @@ class Router implements IRouter {
|
||||||
$application = new App($appName);
|
$application = new App($appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
$application->registerRoutes($this, $routes);
|
return $application;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Test\AppFramework\Routing;
|
namespace Test\AppFramework\Routing;
|
||||||
|
|
||||||
use OC\AppFramework\DependencyInjection\DIContainer;
|
use OC\AppFramework\DependencyInjection\DIContainer;
|
||||||
use OC\AppFramework\Routing\RouteActionHandler;
|
|
||||||
use OC\AppFramework\Routing\RouteConfig;
|
use OC\AppFramework\Routing\RouteConfig;
|
||||||
use OC\Route\Route;
|
use OC\Route\Route;
|
||||||
use OC\Route\Router;
|
use OC\Route\Router;
|
||||||
|
@ -420,7 +419,7 @@ class RoutingTest extends \Test\TestCase {
|
||||||
array $defaults=[]
|
array $defaults=[]
|
||||||
) {
|
) {
|
||||||
$route = $this->getMockBuilder(Route::class)
|
$route = $this->getMockBuilder(Route::class)
|
||||||
->onlyMethods(['method', 'action', 'requirements', 'defaults'])
|
->onlyMethods(['method', 'setDefault', 'requirements', 'defaults'])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$route
|
$route
|
||||||
|
@ -431,8 +430,8 @@ class RoutingTest extends \Test\TestCase {
|
||||||
|
|
||||||
$route
|
$route
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('action')
|
->method('setDefault')
|
||||||
->with($this->equalTo(new RouteActionHandler($container, $controllerName, $actionName)))
|
->with('caller', ['app1', $controllerName, $actionName])
|
||||||
->willReturn($route);
|
->willReturn($route);
|
||||||
|
|
||||||
if (count($requirements) > 0) {
|
if (count($requirements) > 0) {
|
||||||
|
|
Loading…
Reference in New Issue