Following step 2. of #1830854 - [meta] The ESI pipeline battle plan, I am working on the implementation of the described Router object.

Overall goal of this effort is to switch to Symfony's routing framework, but this is only a piece of the puzzle.

Sooner or later some of the code from #1705488 - Implement a generator for Drupal paths may be joined here and it is somewhat blocked by #1269742 - Make path lookup code into an pluggable class.

For starters I will go without generators and pluggable paths.

Comments

g.oechsler’s picture

StatusFileSize
new5.76 KB

Here is a first try. It's implementing a hand full of methods, satisfying a bunch of interfaces. But it's not really doing much.

I'm going to push the code to the wscci sandbox to a branch called 1835762-router.

Status: Active » Needs work

The last submitted patch, 1835762_router.patch, failed testing.

Crell’s picture

Status: Needs work » Needs review

#1: 1835762_router.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1835762_router.patch, failed testing.

g.oechsler’s picture

Status: Needs work » Needs review

#1: 1835762_router.patch queued for re-testing.

Crell’s picture

+++ b/core/lib/Drupal/Core/Routing/Router.php
@@ -0,0 +1,136 @@
+  public function match($pathinfo) {
+    return $this->matchRequest(Request::create($pathinfo));
+  }

I'm not sure if we want to make this method actually work, or just make it fail hard as a note to not do that. Hm.

+++ b/core/lib/Drupal/Core/Routing/Router.php
@@ -0,0 +1,136 @@
+  /**
+   * Gets the RouteCollection instance associated with this Router.
+   *
+   * @return RouteCollection A RouteCollection instance
+   */
+  public function getRouteCollection() {
+    // Right now I have no idea what to return here. Let's just return something
+    // that complies with the docs.
+    return new RouteCollection();
+  }

Ugh. Which interface demands this? We should probably throw an exception here, since our route collections will be too big to return.

Also related: https://github.com/symfony/symfony/pull/5895

g.oechsler’s picture

StatusFileSize
new5.86 KB

I disabled match() and getRouteCollection(), which is part of RouterInterface btw., by throwing an Exception. I added some info about that in the docs.
For now it looks like I'll have to wait for issues to resolve or pull request to be merged.

g.oechsler’s picture

Issue tags: +WSCCI
StatusFileSize
new7.7 KB

The Router now takes a generator in the constructor and passes generate() calls to it.

As there is still no generator I mocked one for testing, just like the MockMatcher.

Crell’s picture

Nice.

I think we need to wire this into the DIC in this patch, which means having a noop Generator object that we can inject into it. So:

1) Create a UrlGeneratorInterface-compliant object that does nothing but throw exceptions if you try to use it.
2) Add a "router" service to the DIC that takes the current matcher and that new temp generator as dependencies.
3) Rewrite the DIC so that router object is what is passed to RouterListener, rather than passing the matcher directly.
4) Profit!

g.oechsler’s picture

StatusFileSize
new10.35 KB

I took care of the first three points and look forward to see the fourth happen!

Crell’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/CoreBundle.php
@@ -99,7 +104,7 @@ public function build(ContainerBuilder $container) {
-      ->addArgument(new Reference('matcher'))
+      ->addArgument(new Reference('router'))

One change. This suggests we should be renaming matcher to router.matcher, for consistency with router.generator.

Once that's done, this is RTBC.

g.oechsler’s picture

Status: Needs work » Needs review
StatusFileSize
new1.11 KB
new10.68 KB

Renamed matcher to router.matcher.

Status: Needs review » Needs work

The last submitted patch, 1835762_router.patch, failed testing.

g.oechsler’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new12.16 KB

Who would have guessed that renaming the router service is breaking the site. :P Registering the chained matchers to the renamed service now.

lars toomre’s picture

+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterMatchersPass.phpundefined
@@ -12,21 +12,21 @@
+ * Adds services tagged 'chained_matcher' to the 'router.matcher' service.

This a bit puzzling... When should one use a '_' in a service name and when should one use a '.' separator? Is perhaps 'chained_matcher' mis-named?

g.oechsler’s picture

'chained_matcher' is not a service! It is just a tag, an arbitrary (yet meaningful) string to mark a service for registration with an other service.

'router.matcher' is a service. It's the matcher service which is part of the router service. You will find other subsidiary services like 'router.generator' and 'router.builder' in CoreBundle. One might argue that services like 'nested_matcher' should be named 'router.nested_matcher'. This might be true or not, but it is surely out of scope of this issue.

lars toomre’s picture

Thanks @g.oechsler for the explanation.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Domo arrigato, Mr. Testboto.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Can someone remind me why this is needed? It was my impression we could just subclass and override the one method that needed the generator but perhaps I'm mis-remembering. There's no explanation of why this is needed in the meta-issue either (except for the functional generator not being in yet, but that's not really a justification for committing a bunch of code that just throws exceptions when you try to use it).

g.oechsler’s picture

It was my impression we could just subclass and override the one method that needed the generator but perhaps I'm mis-remembering.

My first implementation was just like this. It's absolutely possible to go without a generator.

On the other hand a router combines a matcher and a generator, passing the respective method calls to these objects. This is implemented and tested (see the MockGenerator in RouterUnitTest), so the Router is perfectly ready to operate with whatever generator comes along. While #1705488 - Implement a generator for Drupal paths is postponed, we need something to put into the router, just to satisfy the signature of the constructor.

Removing the noop generator unnecessarily cripples the router, which will possibly look exactly like this, once the full blown generator ships.

In short: It's not the router's fault that the generator issue is postponed.

catch’s picture

OK let me put it a different way. What issue is this blocking that it can't wait on the generator patch and needs a dummy generator as a stop-gap?

Crell’s picture

We will need to do this in order to remerge with the upstream Symfony CMF Routing component, which we want to do: https://github.com/symfony-cmf/Routing/pull/30. That is not ready for us to do yet, of course, but is on the roadmap.

As is, no, this issue doesn't add any new functionality yet, and nothing would be harmed in the near term by eliminating the dummy generator and inlining all of the "don't use this yet" exceptions. That's why this is only "normal". :-)

However, I don't see a problem with lining things up for when we can finally bring together the various moving parts here, now that the path issue landed. I am not really wild about the idea of adding a generator, adding a router, merging url() into the generator, moving all of the path alias caching over into generator, refactoring url_rewrite_outbound_alter(), adding HttpCache, and possibly refactoring our code around what happens in CMF Routing all in one go. (I think that's all of the bits and pieces involved in this line of work.) I'd rather build toward that incrementally, so more people can be involved.

If you really want to just sit on it and do the entirety of it at once, fine, say so explicitly. But I respectfully disagree, if for no other reason than it reduces the number of people who are logistically able to be involved in it. (Plus, it will probably be harder to do.)

Crell’s picture

Status: Needs review » Closed (duplicate)

The all-at-once issue is here: #1874500: CMF-based Routing system

Closing this as a duplicate.