joomla/joomla-cms — pull request #2538 by Hackwar (2013-11-17 14:52:32+00:00)
Title: Implementing class based component routers

This implements classes for the component routers. Up till now the routers were based on two functions that the component had to provide, now a component should provide one class which extends from the JComponentRouter interface and provides the two methods build() and parse(). The benefit is, that developers now can extend from a base class and thus abstract some of the code out into those base classes. In a future PR, we can then implement a generic base class, which does most of the heavy lifting for the component routing.

Component developers now must simply wrap their routers in a class named Router, which implements the interface JComponentRouter. They can provide fallback functions that create an instance of that class and execute the build() or parse method. The code could look like this:

class ExampleRouter implements JComponentRouter
{
public function build(&$query) {...}
public function parse(&$segments){...}
}

function ExampleBuildRoute(&$query) {$router = new ExampleRouter; return $router->build($query);}
function ExampleParseRoute($segments) {$router = new ExampleRouter; return $router->parse($segments);}

That way, components can handle both the old and the new routers.

For legacy or missing routers, we have the JComponentRouterLegacy class, which wraps those old routers or provides an empty router in case the component does not provide one.