-
-
Notifications
You must be signed in to change notification settings - Fork 364
[LiveComponent] Send live action arguments to backend #218
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
Conversation
2a86509
to
d07fc81
Compare
Added some tests, but I trully don't understand how they works, so just adopted from existing test :D |
d07fc81
to
f76b97f
Compare
d210ef1
to
05aff8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this!
I left a few comments (and thanks for adding the test). There's one important piece missing, and it's on the server-side. We can't allow ANY values to be passed to the server, because then people could do something like ?values=_controller=App\SomeController::action
. That's because values
is added to $request->attributes
.
So, this needs to be an "opt in" situation. I mentioned in the issue:
We need to add a way to "allow" certain action arguments to be "passable" from the frontend
Probably this would be via an attribute above the action, like:
#[ActionArgument('someValue')]
public function updateUser(string $someValue)
{
}
Then, before adding the ?values
to $request->attributes
(this happens in LiveComponentSubscriber
), we would check the controller for these attributes, and only add the ones allowed.
I also thought about doing this "automatically"... by reading the arguments on the controller and allowing any that are actually there (e.g. in the example above, we would see there is a $someValue
argument and automatically allow someValue
to be passed as a value... but I'm not confident from a security standpoint).
What if we would not directly append to the And: currently symfony argument value resolver injects the values from attributes, so |
05aff8c
to
24776dc
Compare
That's a fantastic idea! I love it! I'd use some attribute named something like
Unless you are using this feature (and if so, give some explanation as to how it's useful to you), we should remove it. And one last thing, can you update the documentation a bit for the new feature? Thanks a lot for this - it's excellent work and you've got excellent ideas! |
Trully - I don't, I only need named args currently :) Ok, will remove, then if someone will have a usecase for this then could be proposed again later :)
Yes, sure, will do tomorrow :)
Yes, wanted just to propose so didn't think much about the attribute name :) But this will be a BC break, but as till now it was not fully supported, I think it shouldn't impact anyone? |
b570b8d
to
53d04cb
Compare
Very true - thank you!
BC break is ok, because we're still experimental. And it's unlikely anyone is using this right now anyways. BUUT, after talking with @kbond, instead of doing your argument resolver, we like a different path (let me explain). But, this full solution doesn't need to be done in THIS PR. At the very least, we should stop merging all of the values into And, we could stop here for this PR if you want to. It would mean the user would need to, for now, use The rest of the solution would involve a new #[LiveAction]
public function updateUser(#[LiveArg] string $someValue, #[LiveArg] string $otherValue, IAmANormalService $service)
{
} The logic would be: We read all of the The reason behind doing this is so that the values can be available to things like FrameworkExtraBundle's param converters. In other words, so that the values work even MORE identically to route Here is a more advanced example that shows off an argument to In HTML:
#[LiveAction]
public function updatePost(#[LiveValue('id')] Post $post)
{
} In this case, |
d18e759
to
d9b5589
Compare
$request->attributes->set('_component', $component); | ||
|
||
if (\is_string($queryString = $request->query->get('args'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed to resolve deprecation: 10x: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated
. Also it would fail with other types, so added sanity check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, let's just return early if not a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were we going to call args
_live_args
?
ef215ff
to
595538b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @norkunas! Just a few minor things.
$request->attributes->set('_component', $component); | ||
|
||
if (\is_string($queryString = $request->query->get('args'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, let's just return early if not a string.
src/LiveComponent/src/EventListener/LiveComponentSubscriber.php
Outdated
Show resolved
Hide resolved
$request->attributes->set('_component', $component); | ||
|
||
if (\is_string($queryString = $request->query->get('args'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were we going to call args
_live_args
?
595538b
to
ab5832a
Compare
I am not sure it's needed anymore as we don't store all args |
Would be nice if cs-fixer in CI would report in files where code style was not followed, because now when running cs fixer it fixes too much unrelated fixes. edit: well now green without any changes in code 🤷♂️ |
ab5832a
to
893c3db
Compare
Ah ok so we aren't going to have the catch all way to grab the raw args from the request? The only way into get them is to inject (or parse the raw args yourself). I don't have a strong opinion on this, I was just curious.
Would be nice to get fabbot on this repo. I realized after I suggested property promotion for the attribute that the cs might fail (think it's a syntax error). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lookin' awesome!
src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php
Outdated
Show resolved
Hide resolved
src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php
Show resolved
Hide resolved
src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php
Show resolved
Hide resolved
@weaverryan what do you think we should do for the failing cs? Easiest solution for this pr is to not use a promoted property for the attribute. I'm thinking switch that out, we can always change later once the cs fixer can handle. |
0b44242
to
b602d12
Compare
I think this is ready :) |
bc1bedb
to
7996e29
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a changelog entry for 2.1?
7996e29
to
46b115d
Compare
Done |
bc62b05
to
fd51cf7
Compare
Will it be merged now? 😝 |
fd51cf7
to
1f0fc2f
Compare
Woohoo! Thank you for this GREAT feature Tomas! |
…(weaverryan) This PR was merged into the 2.x branch. Discussion ---------- [LiveComponents] adding versionadded for action arguments | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | Relates to #218 | License | MIT For #218 - we've recently started adding these to the docs to help highlight why a feature might not work (especially if that feature isn't released yet!) Commits ------- 82b7307 adding versionadded for action arguments
Include to the request to backend the named arguments from live action.