8000 [FrameworkBundle] Integrate custom property accessors into the framework by lrlopez · Pull Request #22191 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Integrate custom property accessors into the framework #22191

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

Closed
wants to merge 4 commits into from

Conversation

lrlopez
Copy link
Contributor
@lrlopez lrlopez commented Mar 27, 2017
Q A
Branch master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR symfony/symfony-docs#6400

This is the last of the two PR related to #18016. It implements changes on FrameworkBundle so it integrates with the new features of PropertyAccess.

Builds will fail because the new component code has not been merged in this branch in order to ease the review. Should the review be positive, I will rebase this with #22190 so they can work together.

@lrlopez lrlopez changed the title [FrameworkBundle] Integrate custom property accessors into the framework [FrameworkBundle] Integrate custom property accessors into the framework (WIP) Mar 27, 2017
@nicolas-grekas nicolas-grekas added this to the 3.x milestone Mar 28, 2017
@lrlopez
Copy link
Contributor Author
lrlopez commented Apr 4, 2017

@dunglas Done!

@lrlopez lrlopez changed the title [FrameworkBundle] Integrate custom property accessors into the framework (WIP) [FrameworkBundle] Integrate custom property accessors into the framework Apr 9, 2017
@nicolas-grekas nicolas-grekas changed the base branch from master to 3.4 May 23, 2017 16:59
@lrlopez
Copy link
Contributor Author
lrlopez commented Aug 1, 2017

Minor correction to RegisterComponentMapping so it can be merged to 3.4. Failures in the builds seem to be unrelated to the PR.

@lrlopez
Copy link
Contributor Author
lrlopez commented Aug 1, 2017

@dunglas time for another review? I'm leaving for holidays in a few days and I'd like to close this PR along the way

@lrlopez
Copy link
Contributor Author
lrlopez commented Sep 24, 2017

@fabpot Fabien, are you still interested in including this feature in Symfony 3.4? Kévin seems to be busy and feature-freeze deadline is almost here. I'd rather not miss it again...

Should that be the case I'll rework the PR so it can be rebased to the 3.4 branch. Thanks!

@lrlopez lrlopez force-pushed the property-access-framework branch 2 times, most recently from 087747a to e948620 Compare September 27, 2017 20:25
@lrlopez
Copy link
Contributor Author
lrlopez commented Oct 3, 2017

I'm working on turning the builds green...

@lrlopez lrlopez force-pushed the property-access-framework branch 7 times, most recently from bc95a83 to fe9b784 Compare October 4, 2017 09:03
@lrlopez
Copy link
Contributor Author
lrlopez commented Oct 4, 2017

I'm puzzled with the failed test on PHP 7.x. Can somebody throw some light on how debug it?

@xabbuh
Copy link
Member
xabbuh commented Oct 6, 2017

You will need to add the PropertyAccess component to the composer.json file of FrameworkBundle with a minimum required version of 3.4 (i.e. add something like 'symfony/property-access': '~3.4|~4.0' to the require-dev section).

@lrlopez
Copy link
Contributor Author
lrlopez commented Oct 6, 2017

I've tried that, but the failed test is still there. Well, changes to PropertyAccess component haven't been merged into the 3.4|4.0 branch yet, so I think is futile: a chicken and egg situation. We'll try to merge a copy of the changes into the repository in order to cheat composer. If it works I'll post the link to Travis-CI test results

@xabbuh
Copy link
Member
xabbuh commented Oct 6, 2017

Our Travis config makes sure that the components are taken from the PR for the deps=low build. The failure must have been something else then.

@lrlopez lrlopez force-pushed the property-access-framework branch 2 times, most recently from 7fcdcd8 to 544e466 Compare October 6, 2017 19:14
@lrlopez
Copy link
Contributor Author
lrlopez commented Oct 6, 2017

@xabbuh ,
Then I'm confused... Tests pass now when I force the updated PropertyAccess component in composer.json 😕

@@ -15,6 +15,12 @@
"homepage": "https://symfony.com/contributors"
}
],
"repositories": [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes are only temporary until the PR is accepted or until PR #22190 is merged...

@nicolas-grekas
Copy link
Member

blocked by pending review on #22190
@lrlopez this might be moved to 4.1 because we're already late in feature freeze time and the PR is significant
Would it be an issue to merge #22190 in terms of BC? Or does this one adds on top seamlessly, without changing any public/protected interface?

@lrlopez
Copy link
Contributor Author
lrlopez commented Oct 8, 2017

@nicolas-grekas #22190 does not introduce any BC issues (or at least it should not). There is an additional (and optional) parameter into the constructor of a PropertyAccessor class, but if nothing is used the behaviour is 100% equivalent to the previous one.

#22190 was already reviewed by @HeahDude and was only pending on some changes that are already addressed.

This feature will be useful to my students, as they are not proficient in English and find problems with the current singularization rules when creating entities. They'll be very grateful it could be merged into 3.4 which is LTS and still works with PHP 5.6/7.0. I'll commit it as many personal time as I'm able to if necessary to help you on that during the stabilization phase. Thanks!

@xabbuh
Copy link
Member
xabbuh commented Oct 9, 2017

This feature will be useful to my students, as they are not proficient in English and find problems with the current singularization rules when creating entities.

For that case, wouldn't #23789 be of use for them too? This makes me wonder if we really need both PRs #22190 and #23789. And if we don't need both we should make a careful decision of which PR to merge.

@lrlopez
Copy link
Contributor Author
lrlopez commented Oct 9, 2017

For that case, wouldn't #23789 be of use for them too? This makes me wonder if we really need both PRs #22190 and #23789. And if we don't need both we should make a careful decision of which PR to merge.

Ok, I see the struggle here.

The problem with #23789 is that you must create a new naming strategy per project even if you're interested in just overriding just a pair of accessors. It would be a little overkill for my students, but is a viable solution (annotations are more intuitive for them, though). In fact, my first approach a couple of years ago was similar to David's one (see PR #15766) but Fabien decided that defining PropertyAccess options was the way to go (#5013). That was the seed of #22190.

Both #23789 and #22190 address some issues in a different way (i.e. singularization) and in any scenario one could be better than the other one, but there is no silver bullet that works best on every scenario.

Each of the approaches have different pros & cons. Let's start with some of them and we can add more as the discussion moves forward:

Custom naming-strategy (#23789)

Pros:

  • Much simpler.
  • Affects all the accessors at once.
  • You can extend (or partially replace) the original behaviour by extending a class, which is intuitive.

Cons:

  • Doesn't allow to implement virtual properties.
  • Changing just a particular accessor implies writing PHP code.
  • The custom naming strategy must be global to the project, which could potentially affect other bundles.

Custom property accessors (#22190)

Pros:

  • Allows defining virtual properties (i.e. calculated ones).
  • If using annotations, configuration is next to the affected property or method (is also possible to configure with XML or YAML).
  • It does not unintendedly affect any other bundles because it doesn't change the default property access behaviour.

Cons:

  • Includes a lot (and I mean a lot) of code changes because it needs to extract metadata from annotations, XML and YAML (in fact most code changes are related to this). For speed reasons, also a cache pool must be used.
  • Can't affect all the accessors at the same time, you must define them case-by-case.

Anyway, I don't think both approaches are incompatible but in fact complement each other. Granularity is the key here: sometimes a custom (and global) naming strategy could be the best solution and in others changing a couple of accessors could be just enough.

@DavidBadura
Copy link
Contributor
DavidBadura commented Oct 9, 2017

Another use case for NamingStratgy: controlling of camelizing (exists this Word?)

I use the Serializer (ObjectNormalizer) a lot. There is a problem with the interplay of PropertyInfo, PropertyAccess and Serializer (see PR #23656).

My suggestion was to add a new option "don't camelize", so you can create a special PropertyAccessor for the Serializer component. But one flag for one special usecase is bad. Instead of adding a flag, with #23789 you can change the strategy.


But as @lrlopez said, the features complement each other perfectly. I also have use cases where annotation is much easier and better. And would love to see this in the core. But not everything can be solved well with annotation. Actually, everything you want to change Global (for one PropertyAccess instance).

@lrlopez
Copy link
Contributor Author
lrlopez commented Oct 11, 2017

Until a decision is made, do I need to make any additional changes to the PR? The "Needs work" label is still assigned to the issue

@lrlopez lrlopez force-pushed the property-access-framework branch 2 times, most recently from 544e466 to 148985f Compare November 6, 2017 08:45
@lrlopez lrlopez force-pushed the property-access-framework branch from 148985f to 91d9d74 Compare November 6, 2017 12:37
@chalasr chalasr modified the milestones: 3.4, 4.1 Nov 9, 2017
@chalasr
Copy link
Member
chalasr commented Nov 9, 2017

Status updated and milestone changed to 4.1 where PHP7.1 features can be used.

@nicolas-grekas nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
@fabpot fabpot modified the milestones: 5.4, 6.1 Nov 16, 2021
@nicolas-grekas
Copy link
Member
nicolas-grekas commented Feb 14, 2022

I'm closing because this staled and something like #22190 should be added first IIUC.
@lrlopez (or anyone else really) PR welcome if you're still interested in seeing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0