contao/module-core — pull request #18 by tristanlins (2014-11-02 16:42:02+00:00)
Title: Implement backend and frontend routing

And finally here we goes! This PR implements backend and frontend routing, because both depend on each other.

The backend routing was original loaded through the `app/config/routing.yml`. Now it is autoloaded by the new [`BundlesLoader`](https://github.com/tristanlins/contao-module-core/blob/feature/cmf-routing/src/Routing/BundlesLoader.php), the usage is [documented here](https://github.com/tristanlins/docs/blob/4.0/symfony/en/Routing.md#define-static-routes).

The frontend routing is done through the CMF router.

I add a custom [`ChainedRouteProvider`](https://github.com/tristanlins/contao-module-core/blob/feature/cmf-routing/src/Routing/ChainedRouteProvider.php) to give the ability of providing multiple providers at once. The usage is [documented here](https://github.com/tristanlins/docs/blob/4.0/symfony/en/Routing.md#define-a-cmf-provider). The chain provider is only used if its needed, see [AddRouteProvidersPass:53-56](https://github.com/tristanlins/contao-module-core/blob/feature/cmf-routing/src/DependencyInjection/Compiler/AddRouteProvidersPass.php#L53-L56).

The [`PageRouteProvider`](https://github.com/tristanlins/contao-module-core/blob/feature/cmf-routing/src/Routing/PageRouteProvider.php) generate the routes for the page structure. The real generation of the routes is decoupled through events. The [`CreatePageRoutesSubscriber`](https://github.com/tristanlins/contao-module-core/blob/feature/cmf-routing/src/Routing/CreatePageRoutesSubscriber.php) create the routes for the default page types. Extension developers can use the event to create their own routes for the custom types.

**Open questions and TODOs**

* [ ] Support fallback to regular page routing for custom types?!
* [ ] Support custom page types in the `FrontendController`.
* [ ] Redirect `index` page to `/` url?!
* [ ] Thanks to the redirecting backend entry points, e.g. `contao/main.php`, the referrer logic and so the "back"-link is broken :-\

I wrote a documentation draft, you can see it here: https://github.com/contao/docs/pull/176

Related to https://github.com/contao/contao/pull/32