Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch away from fatfree for routing #1265

Closed
jtojnar opened this issue May 23, 2021 · 5 comments
Closed

Switch away from fatfree for routing #1265

jtojnar opened this issue May 23, 2021 · 5 comments

Comments

@jtojnar
Copy link
Member

jtojnar commented May 23, 2021

Slowly tearing fatfree out of the codebase.

We should probably wait for after 2.19 so that we can stuff depending on use newer PHP.

Alternatives:

See also:

jtojnar added a commit that referenced this issue Dec 22, 2021
One less dependency on F3

Fixes: #1265
@kktsvetkov
Copy link

@jtojnar I've created a new router, https://github.com/ertuo-php/ertuo -- Are you interested to have a look ?

@jtojnar
Copy link
Member Author

jtojnar commented Dec 27, 2021

@kktsvetkov Interesting concept. Unfortunately, selfoss still targets PHP 5.6 for now so we cannot use it. I hope to bump target version soon and then I will re-evaluate.

Could you clarify few points?

  • The keys of the iterable callback output are used to find the next route in the step by step process.

    Still do not understand what are the keys used for other than the default route.

  • How does the tree select a route when multiple child route groups in a route group match?

  • What other routing frameworks did you look at? It reminds me of https://remix.run/blog/react-router-v6

  • Why are you using '' key with both fallback (404) and empty chunk?

  • It is not clear to me how to attach handlers and dispatch those – I feel like the Result is internal detail I should not need to care about.

    • Am I supposed to attach handlers using attributes, get the matched handler from Result and run that manually?
    • The methods are only ever mentioned in https://github.com/ertuo-php/ertuo#route-methods but no idea how does it tie in with anything else. Does it set some attributes?

@kktsvetkov
Copy link

@jtojnar Thanks for having a look at it!

  • Still do not understand what are the keys used for other than the default route.
  • How does the tree select a route when multiple child route groups in a route group match?

These two are related. The keys are used to select the next child route.

  • What other routing frameworks did you look at?

Only PHP libraries. The main focus was on Fast Route and Symfony as the most popular ones.

  • Why are you using an empty key with both fallback (404) and empty chunk?

The fallback is not really a 404, it is a default value you might want to use instead. I wanted to have the route tree configuration as simple as possible and re-using the empty key kind of makes sense as in both cases (no match or empty step) there is nothing accepted.

  • It is not clear to me how to attach handlers and dispatch those

It is the same concept Symfony is using. At the end of the dispatching, they have an array with parameters, and some of the parameters are "reserved" as they carry the handler that should be called.

The methods corresponding to HTTP verbs do indeed set some attributes. At the end of dispatching, it is just like you put it -- you get the matched handler from the result attributes and call it.

@jtojnar
Copy link
Member Author

jtojnar commented Dec 29, 2021

  • Still do not understand what are the keys used for other than the default route.
  • How does the tree select a route when multiple child route groups in a route group match?

These two are related. The keys are used to select the next child route.

It is not obvious to me from the README how are they used to select next child. Oh, I see now. The exploded parts are looked up in the iterable. Maybe the README could emphasize this point.

  • It is not clear to me how to attach handlers and dispatch those

It is the same concept Symfony is using. At the end of the dispatching, they have an array with parameters, and some of the parameters are "reserved" as they carry the handler that should be called.

In Symfony, you directly set controller on the route you create and that then gets dispatched somehow.

$routes->add('api_post_show', '/api/posts/{id}')
        ->controller([BlogApiController::class, 'show'])
        ->requirements(['id' => '\d+'])
        ->methods(['GET', 'HEAD']);

I understand that running the controller is not actually a goal for a routing library but I feel it would still be useful to show a simple example of that.

@kktsvetkov
Copy link

Thanks, this is good feedback.

The README is a struggle, as it is not my strongest part to explain how things work. I've written a couple of articles trying to get into more details:

The methods and controller thing, perhaps for the same route (user/123) there will be different action methods associated with the different HTTP verbs. I don't want to repeat things in route declarations, so the best thing I came up with was to attach these pairs of HTTP methods and action callbacks:

yield '' => Route::add()
	->get('BlogPost::show')
	->post('BlogPost::update') ...

This is in the README, but obviously, it is not obvious 😎 Since a day or two ago I also added Route::any() and Route::match() and I just have to figure out an easier way to actually extract the controller action. Calling the action is a bit more nuanced since different projects and frameworks pass different things, not only the Request object for example but some DI stuff as well. It is better if each decides how to handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants