Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Add a TypeGuesser that use typed property reflection#47450

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jvasseur wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromjvasseur:reflection-type-guess

Conversation

jvasseur
Copy link
Contributor

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
Tickets
LicenseMIT
Doc PR

When using form on objects that are not doctrine entities, you have to explicitly define all types that are used on forms.

This PR adds a type guesser that uses reflection information from typed properties to guess form types.

LJaschinski and predakanga reacted with thumbs up emoji
@carsonbotcarsonbot added this to the6.2 milestoneSep 1, 2022
@jvasseurjvasseur changed the title[Fom] Add a TypeGuesser that use typed property reflection[Form] Add a TypeGuesser that use typed property reflectionSep 1, 2022
@carsonbot
Copy link

Hey!

I think@alamirault has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

['string', new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE)],
['nullable', new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE)],
['suit', new TypeGuess(EnumType::class, ['class' => Suit::class], Guess::MEDIUM_CONFIDENCE)],
['date', new TypeGuess(DateTimeType::class, ['input' => 'datetime_immutable'], Guess::LOW_CONFIDENCE)],
Copy link
Member

Choose a reason for hiding this comment

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

we should also add a test case for a type where the guess would benull

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I've added one case with a property typed with an unknown class, and one with an untyped property.

@jvasseurjvasseurforce-pushed thereflection-type-guess branch 2 times, most recently from5d2411a toac8a91dCompareSeptember 8, 2022 10:28
{
public function guessType(string $class, string $property): ?TypeGuess
{
$type = $this->getReflectionType($class, $property);
Copy link
Member

@dunglasdunglasSep 9, 2022
edited
Loading

Choose a reason for hiding this comment

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

Shouldn't we use PropertyInfo instead of using reflection directly? This will allow supporting Reflection but also PHPDoc/PHPStan types as well as other metadata sources.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I thought about using PropertyInfo but decided not to because I wanted the guesser to be the simplest possible and not depend on another component (this could be important when not using the full stack framework).

@nicolas-grekasnicolas-grekas modified the milestones:6.2,6.3Nov 5, 2022
@jvasseurjvasseurforce-pushed thereflection-type-guess branch 2 times, most recently from3f14eac tofbf29b9CompareNovember 9, 2022 09:28
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dunglasdunglasdunglas left review comments

@OskarStarkOskarStarkOskarStark left review comments

@xabbuhxabbuhxabbuh left review comments

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

7 participants
@jvasseur@carsonbot@dunglas@OskarStark@xabbuh@fabpot@nicolas-grekas

[8]ページ先頭

©2009-2025 Movatter.jp