-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Value resolver #95
Value resolver #95
Conversation
Furthering on my comments from #91, 7ca9348 adds an important feature. Previously, only when persisting What this potentially allows is: public function updateProfileImage(
User $user,
EntityManagerInterface $em,
#[UploadedFile(
filesystem: 'temp'
constraints: new ImageConstraint(maxWidth: 500, maxHeight: 500),
errorStatus: 422, // this would be the default
)]
Image $image,
): Response {
$user->setProfileImage($image);
$em->flush();
return new Response(...);
} In the above specific scenario, it's probably better to use a |
a52bc65
to
bb37879
Compare
@kbond Nice! Mentioned features makes most of my other PR pretty obsolete, so let's leave it aside for now. I have tweaked and empowered value resolver quite a bit. Code is better organized in my opinion and is easier to extend. I have left storing to filesystem for now as I need to wrap my head around it. But the validation logic is now in place (it throws Unfortunately the syntax for constraints in attributes is only available from PHP 8.1 forward ( https://www.php.net/releases/8.1/en.php#new_in_initializers ). I can try to skip some tests on PHP 8.0 or we can bump required PHP version (that'd be on par with Symfony 6.1+) - I leave the decision to you. The problems I see with storing files to filesystems:
Also I think it could be useful to have own All in all it needs a bit more love, but is shaping nicely. |
I think I have a take on this "store on serialization" concept. How about going this way: Create a
Creating such a closure in a value resolver phase is as simple as storing file (in fact it's the same logic, but wrapped in a closure). (same for What do you think of such approach? |
What about allowing pendingfile to be lazy? Then we can wrap it in a serializedfile if you want to serialize it? |
Wouldn't that store the file on access and not serialization? I admit I didn't analyze |
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.
Also I think it could be useful to have own HttpException for this case, so that it is possible to configure logging of it on a framework (see tests - right now they log errors during validation testing).
This is because throwing the HttpException generates logs?
I think we should leave it up to the user - they can configure this behaviour in framework/monolog config IIRC.
I've handled the test output in a few other libraries by setting a null logger: https://github.com/zenstruck/browser/blob/e46f25ae96f8a6b67ce2f547f6d4e6b24398a9a8/tests/Fixture/Kernel.php#L205
I'm having a hard time understanding what you'd like to achieve with "store on serialization". Is it related to live components or another use-case? I've been thinking about the lifecycle of a
|
Thanks for the review! Regarding the serialization...
Well, I completely forgot about this one when crafting the solution. Thank you for pointing this out, I admit to being wrong 👍 With that settled I think I will be able to finalize the PR next week without all this "store on serialize" madness 😸 |
tests/Filesystem/Symfony/HttpKernel/PendingDocumentValueResolverTest.php
Outdated
Show resolved
Hide resolved
tests/Filesystem/Symfony/HttpKernel/PendingDocumentValueResolverTest.php
Outdated
Show resolved
Hide resolved
tests/Filesystem/Symfony/HttpKernel/RequestFilesExtractorTest.php
Outdated
Show resolved
Hide resolved
tests/Filesystem/Symfony/HttpKernel/RequestFilesExtractorTest.php
Outdated
Show resolved
Hide resolved
Ok, glad we're on the same page now! It can wait for a later PR but the reason I was thinking of adding |
Sure, they will be very simple to provide when we want to store file as soon as possible instead of as late as possible. I will add them 👍 |
Thinking we should have both |
70087e1
to
bd28607
Compare
I think I have done everything (but maybe more tests and docs obviously). I have indeed created separate attributes for pending file and stored one, so that distinction is obvious.
I have finally decided to add custom exception class. This is to actually allow configuring it's severity and on framework level. The config there is keyed by an exception class, so using I also added the property to attributes. I'm unsure if that's required by live components (I need to catch up with live components development soon), but doesn't hurt to have it in place. When we'll have this one settled I'll jump back in to UX to see what happened in recent months. I think file uploads are still unhandled. If that's the case I'll start with frontend code only in hope that it'll be enough to use this library. Anything more will be added value 🎉 |
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.
Really liking this - I can use this in my app right away!
I have finally decided to add custom exception class.
This is a good call. To clarify, by default, it will throw a 422, you can adjust the error code on a controller-by-controller basis or set your framework config to globally intercept/adjust?
…non functional yet!)
Co-authored-by: Kevin Bond <[email protected]>
35a1f30
to
1874fb5
Compare
I'm sorry it took so long to get back here.
I went step ahead. The exception now extends I think the last topic is the temporary file location that we can discuss in its topic |
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.
Just a few last minor things, then let's merge!
Co-authored-by: Kevin Bond <[email protected]>
Both are commited and phpstan is made happy 😄 |
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.
Awesome, thanks Jakub!
This is extraction of value resolver from #91, without anything new and fancy 😸