Page MenuHomePhabricator

Remove Module/Route dependency from Handler
Open, Needs TriagePublic

Description

Split off from my comment on T405373:

I wonder how hard it would be to remove the following methods/dependencies from Handler:

  • getModule(): callers use this to get the module prefix or deprecation flag/timestamp. These can be injected instead. There could be a Hander::getModulePathPrefix() that returns the injected module prefix string.
  • getRouter(): callers use this to then call Router::isRestbaseCompatEnabled() or Router::getRouteUrl()/Router::getRoutePath(). The former could be replace by a static RestbaseCompat::isRestbaseCompatEnabled() helper method. The later could be replaced by injecting a RouteLocator object for making paths/URLs for routes, which would not depend on Router. CreationHandler::mapActionModuleResponse could use $this->getRouteLocator()->getRouteUrl( '/v1/page/' . $title ). RedirectHandler could use $this->getRouteLocator()->getRoutePath( $path, $pathParams, $queryParams. It's interesting how many Handlers assume that some specific Handler exists at some hard-coded path (e.g. AddItemStatementRouteHandler::setLocationHeader or CreationHandler::mapActionModuleResponse). I think that these should be injected via route config instead of being hard-coded in the Handler. Handlers should not assume the location of themselves nor other Handlers.

Getting Module/Router out of Handler would make Handler construction much easier. It would also better justify a HandlerFactory since there would not already be a Router instance for use in ModuleSpecHandler.

Event Timeline

aaron removed Atieno as the assignee of this task.Tue, Dec 2, 4:57 PM
aaron added a subscriber: Atieno.