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

[PropertyInfo] Add an extractor to guess if a property is initializable#26997

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

Merged
fabpot merged 1 commit intosymfony:masterfromdunglas:propertyinfo-constructor
Sep 4, 2018

Conversation

@dunglas
Copy link
Member

@dunglasdunglas commentedApr 21, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRsymfony/symfony-docs#10319

When dealing with value objects, being able to detect if a property can be initialized using the constructor is a very valuable information. It's mandatory to add a proper value object support in API Platform and in the Serializer component.

Seeapi-platform/core#1749 andapi-platform/core#1843 for the related discussions, extended use cases and proof of concepts.

This PR adds a new interface to guess if a property can be initialized through the constructor, and an implementation using the reflection (inReflectionExtractor).

Koc, komik966, tlfbrito, ogizanagi, and damour reacted with thumbs up emoji
*/
publicfunctionisInitializable(string$class,string$property,array$context =array()): ?bool
{
$this->assertIsString($class);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of this?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I added this for consistency with other methods, I'm not sure of the origin intent...

Copy link
MemberAuthor

@dunglasdunglasApr 22, 2018
edited
Loading

Choose a reason for hiding this comment

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

Here is the original intent:#19437

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. So type hints are added now so these checks are redundant

dunglas reacted with thumbs up emoji
/**
* Is the property initializable?
*/
publicfunctionisInitializable(string$class,string$property,array$context =array()): ?bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the use-case for returningnull? Also, shouldn't we explicit within the method name that we are talking about the constructor in here?isInitializableViaConstructor or something like that?

Taluu and shouze reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

null means "we don't know"?

dunglas reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@teohhanhui is right. It means "this extractor cannot guess", try the next registered in the chain. It's mandatory to keep this behavior for consistency with existing interfaces and to provide an extension point.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@sroze I prefer the current name,isInitializableViaConstructor is too verbose and brings nothing much.

Taluu reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

My 2cts are that I didn't understand whatisInitializable meant before reading more about your PR. I can tell you that if I saw this interface I'd think "wait. What is that about?". While theisInitializableViaConstructor clarifies it and is not too verbose.

teohhanhui reacted with thumbs up emojiTaluu reacted with confused emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't, the PhpDoc that you've put is enough (to me).

Copy link
Contributor

@teohhanhuiteohhanhuiJun 30, 2018
edited
Loading

Choose a reason for hiding this comment

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

"Property initializable" on its own indeed makes no sense to me. PerhapsConstructorInitializableExtractorInterface::isPropertyInitializable?

Copy link
MemberAuthor

@dunglasdunglasJul 3, 2018
edited
Loading

Choose a reason for hiding this comment

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

PropertyInitializableViaConstructorExtractorInterface::isInitializable?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we could just stick with the current names. Lol...

dunglas reacted with laugh emoji
Copy link
MemberAuthor

@dunglasdunglasJul 4, 2018
edited
Loading

Choose a reason for hiding this comment

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

@sroze@fabpot ok for you to keep the current names?

@nicolas-grekasnicolas-grekas added this to thenext milestoneApr 22, 2018
Copy link
Member

@lyrixxlyrixx left a comment

Choose a reason for hiding this comment

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

Looks good to me

continue;
if ($property===$parameter->name) {
returnarray($this->extractFromReflectionType($parameter->getType()));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the point of this change ? I know it does the same, but with a different style, but then ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Removing 2 lines and making the code more explicit, but yes it's not mandatory.

Taluu reacted with thumbs up emoji
returnnull;
}

if ($constructor =$reflectionClass->getConstructor()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you test if the constructor is instantiable first?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Good idea, I'll update the code.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

done

interface PropertyInitializableExtractorInterface
{
/**
* Is the property initializable?

Choose a reason for hiding this comment

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

not sure this is useful :)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It's for consistency with other interfaces.

@nicolas-grekas
Copy link
Member

rebase needed (and some comments to address)

@dunglasdunglasforce-pushed thepropertyinfo-constructor branch from88b2286 to17cf6a1CompareJune 30, 2018 08:59
@dunglas
Copy link
MemberAuthor

rebased and comments addressed

/**
* Is the property initializable?
*/
publicfunctionisInitializable(string$class,string$property,array$context =array()): ?bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

My 2cts are that I didn't understand whatisInitializable meant before reading more about your PR. I can tell you that if I saw this interface I'd think "wait. What is that about?". While theisInitializableViaConstructor clarifies it and is not too verbose.

teohhanhui reacted with thumbs up emojiTaluu reacted with confused emoji
@dunglasdunglasforce-pushed thepropertyinfo-constructor branch fromfced167 to6737e71CompareJuly 13, 2018 11:48
@dunglas
Copy link
MemberAuthor

Rebased, I suggest to keep the current name as there are no consensus on another name.

4.2.0
-----

* added`PropertyInitializableExtractorInterface` to test if a property can be initialized through the constructor and an implementation is`ReflectionExtractor`
Copy link
Member

Choose a reason for hiding this comment

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

if a property can be initialized through the constructor (implemented byReflectionExtractor)


if ($constructor =$reflectionClass->getConstructor()) {
foreach ($constructor->getParameters()as$parameter) {
if ($property ===$parameter->name) {
Copy link
Member

Choose a reason for hiding this comment

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

The fact that the constructor parameter name must match the property one should be documented somewhere.

interface PropertyInitializableExtractorInterface
{
/**
* Is the property initializable?
Copy link
Member

Choose a reason for hiding this comment

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

This is probably where we need more docs about the naming convention.

@fabpot
Copy link
Member

@dunglas Do you have time to have a look at my comments?

@dunglasdunglasforce-pushed thepropertyinfo-constructor branch 2 times, most recently fromd125f25 to4a0483dCompareSeptember 4, 2018 11:00
@dunglas
Copy link
MemberAuthor

@fabpot done

@dunglas
Copy link
MemberAuthor

CI errors look unrelated.

@fabpotfabpotforce-pushed thepropertyinfo-constructor branch froma8fb40e to9d2ab9eCompareSeptember 4, 2018 15:17
@fabpot
Copy link
Member

Thank you@dunglas.

@fabpotfabpot merged commit9d2ab9e intosymfony:masterSep 4, 2018
fabpot added a commit that referenced this pull requestSep 4, 2018
… is initializable (dunglas)This PR was squashed before being merged into the 4.2-dev branch (closes#26997).Discussion----------[PropertyInfo] Add an extractor to guess if a property is initializable| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | todoWhen dealing with value objects, being able to detect if a property can be initialized using the constructor is a very valuable information. It's mandatory to add a proper value object support in API Platform and in the Serializer component.Seeapi-platform/core#1749 andapi-platform/core#1843 for the related discussions, extended use cases and proof of concepts.This PR adds a new interface to guess if a property can be initialized through the constructor, and an implementation using the reflection (in `ReflectionExtractor`).Commits-------9d2ab9e [PropertyInfo] Add an extractor to guess if a property is initializable
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedSep 5, 2018
edited
Loading

This PR breaks the CI by breaking BC somehow, see deps=high failures (which mean that 4.1 is broken when using PropertyInfo master)
@dunglas could you have a look please?
(note that we should be careful when merging PRs which have failures)

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedSep 5, 2018
edited
Loading

(fixed in5557e38, we'll have to deal with this kind of BC breaks now that we put DI passes in components and not in bundles anymore.)

@dunglasdunglas deleted the propertyinfo-constructor branchSeptember 5, 2018 14:23
@dunglas
Copy link
MemberAuthor

Thanks for the fix@nicolas-grekas

@javiereguiluz
Copy link
Member

I've createdsymfony/symfony-docs#10272 to document this new feature. Please, don't forget to create a doc issue for every new feature.

Kévin, if you don't have time to contribute the docs, we'll need some code examples of using this feature in action. Thanks!

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestSep 11, 2018
…s initializable (dunglas, javiereguiluz)This PR was merged into the master branch.Discussion----------[PropertyInfo] Add an extractor to guess if a property is initializablesymfony/symfony#26997symfony/symfony#24571Closes#10272.Commits-------8415f96 Minor tweakseebca4a RSTf7ed144 [PropertyInfo] Add an extractor to guess if a property is initializable
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@lyrixxlyrixxlyrixx left review comments

@fabpotfabpotfabpot approved these changes

+5 more reviewers

@teohhanhuiteohhanhuiteohhanhui left review comments

@bendaviesbendaviesbendavies left review comments

@srozesrozesroze left review comments

@meyerbaptistemeyerbaptistemeyerbaptiste left review comments

@TaluuTaluuTaluu approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

11 participants

@dunglas@nicolas-grekas@fabpot@javiereguiluz@Taluu@lyrixx@teohhanhui@bendavies@sroze@meyerbaptiste@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp