dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.85k stars 519 forks source link

Improve PHP 8 Attributes by using named argument constructor annotation #1229

Closed IonBazan closed 3 years ago

IonBazan commented 3 years ago

Using @NamedArgumentConstructor is preferred way to define Annotations which also support PHP 8 Attributes. Instead of manually setting all properties based on $options argument, we should let doctrine/annotations take care about that.

This change actually allows us to force $mapping to be mandatory using native type checks. This also enables us to skip the name of the argument if it's not needed:

#[Vich\UploadableField('dummy_file', fileNameProperty: 'fileName')]

or

#[Vich\UploadableField('dummy_file')]

This however requires doctrine/annotations at v1.12 or higher. Not sure if we should add some checks for that. Perhaps adding it to conflicts section would be enough.

Update: Removed deprecated PHPUnit usage of $this->at(). Tests are no longer depending on the order of method calls.