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

Introduce RequestUtil #2449

Merged
merged 4 commits into from
Apr 8, 2021
Merged

Introduce RequestUtil #2449

merged 4 commits into from
Apr 8, 2021

Conversation

askvortsov1
Copy link
Member

Fixes #869

Abstracts access to following request attributes:

  • actor
  • session
  • locale
  • route name

Are there any attributes on here that we're missing (or that we should exclude)? $actor is the biggest one that needs to be abstracted away IMO, do we even need the others?

Copy link
Member

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't all methods supposed to be static ?

@askvortsov1
Copy link
Member Author

Yeah, also I haven't changed any of the usages in the code yet. Actually I should have put this in the issue as a comment (since I just want to confirm which attributes we want to provide an API for) not as a PR, not sure what I was thinking

Abstracts access to following request attributes:

- actor
- session
- locale
- route name

class RequestUtil
{
public static function getActor(Request $request): User
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a branch lying around somewhere that basically does the same thing, but more along the lines of Actor::fromRequest(). I liked that a lot. Maybe you like the idea, too? 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw more discussion in #2703 and related tickets. Have fun. 😀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actor is sensible too, but I prefer RequestUtil because:

  • While getting it is clean, setting it results in clunky naming, as with the user method.
  • If we need to encapsulate more stuff, we don't need to add more util classes / force people to import as much stuff. Perhaps separate classes is slightly better with respect to single responsibility, but I think encapsulating request data is still fairly granular. Better than adding it onto User anyhow 🙈

@askvortsov1 askvortsov1 merged commit 94d69fe into master Apr 8, 2021
@askvortsov1 askvortsov1 deleted the as/request-util branch April 8, 2021 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to a custom subclass of ServerRequest
4 participants