-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add Inflector component (from StringUtil of PropertyAccess) #18260
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
Conversation
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" |
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.
should be current
, not 4.1
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.
Every other component uses 4.1
though. Perhaps this should be addressed in a separate PR (if it's an issue)?
d85bcad
to
9695e78
Compare
We need to keep some legacy test for the StringUtil class |
@@ -0,0 +1,19 @@ | |||
Copyright (c) 2012-2016 Fabien Potencier |
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.
The year is 2012 based on 7837f50
Should the test be duplicated? |
no need to duplicate the whole tests (as the new component is tested). But we at least need a simple test, which would catch mistakes in the BC class |
What about using Doctrine Inflector library instead of creating a new component? |
@javiereguiluz To me that'd be preferable too. But we need to use the same inflector for both PropertyAccess and PropertyInfo, according to @dunglas: #18166 (comment) And if we switch both to the Doctrine Inflector, how should we handle the BC break? |
I think it would be preferable for the community to use only 1 inflector library. Would it be an idea to use the doctrine variant instead and start patching that one to cover more use-cases when needed? |
How do we handle the BC break? Or would it not be considered a BC break? 😜 |
@teohhanhui I don't see why it would be. You can leave the deprecation as is and leave the tests as is. If the tests fail, you can patch those missing use-cases in the doctrine inflector. The only BC break would be tests failing because the doctrine inflector misses cases, but you will find out by hooking it up. |
@iltar I'm thinking BC breaks for applications due to different result of the singularization. It seems impossible for us to catch them all... |
But alas, it'd be for the best. What do you think, @dunglas? |
How could be any difference if both libraries supposedly do the same: transform English words into/from singular/plural? |
Given that the conversion rules are quite complex, they may behave differently for some cases (common rules should work fine, but the component would be useless if the rule was as simple as removing the final |
If the application previously used the wrong singular form which matches what is produced by It's not really possible for us to ensure consistent before/after results. Now the question is whether this is part of our BC promise (of course, surprises like this would still be unwelcome and annoying for an application developer). |
Luckily we have tests to verify the symfony variant still works, if they pass, no problem. If they fail: patch the inflector on doctrine's side. |
The compatibility test between both library would be as follow:
Test failures there would show us known incompatibilities (we may still have incompatibilities in things not covered by any of the testsuites). This would help us to make the decision. |
There are many failures: https://travis-ci.org/teohhanhui/symfony/jobs/117700871#L4206-L4791
edit: Yes, there are still some valid use cases: https://www.quora.com/What-is-the-plural-of-axis |
After clean-up: https://travis-ci.org/teohhanhui/symfony/jobs/117721231#L4099-L4348 There are still a number of failures, and a few that we have no real way of fixing in the Doctrine Inflector (multiple words with the same plural form):
|
And this is the difference between the doctrine inflector and the Symfony StringUtil: the doctrine inflector aims to provide a single singular string (which make sense as their primary usage of the inflector is generating method names during code generation, so they must settle on a single singular), while the goal of the StringUtil is to find all potential singular, to be able to call the method named by the developer with one of them. and this difference of goal of the project is probably the main reason why we won't be able to switch to doctrine/inflector (as they won't change the focus of the Doctrine project just to allow us to use it) |
@stof It looks like I have to continue with this PR then... |
9695e78
to
11f5c30
Compare
@teohhanhui Do you think you can finish (not sure what's left) this PR is the next couple of days? I'd like to get this in for 3.1 as it seems quite easy to acheive. Marking the whole component as being internal also gives us the opportunity to add more or even drop it if we find a better replacement in the meantime. |
What else do I need to do, other than adding |
11f5c30
to
8c78b2c
Compare
Marked as internal and added a disclaimer in the README |
8d9de9b
to
10e2771
Compare
Rebased. |
10e2771
to
0c69e72
Compare
@@ -0,0 +1,19 @@ | |||
Inflector Component | |||
====================== |
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.
Extra =
s here
👍 (after the minor comments have been fixed) |
0c69e72
to
9dbc0b4
Compare
/** | ||
* Creates singulars from plurals. | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
* | ||
* @deprecated Deprecated since version 3.1, to be removed in 4.0. Use {@see \Doctrine\Common\Inflector\Inflector} instead. |
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.
Telling people to use Doctrine Inflector does not make sense here as the feature is not the same. And in fact, we are creating a new component exactly for this reason: we cannot use Doctrine inflector. So, the recommendation should be to use the new component instead.
9dbc0b4
to
8abebf6
Compare
👍 |
Thank you @teohhanhui. |
…cess) (teohhanhui) This PR was merged into the 3.1-dev branch. Discussion ---------- Add Inflector component (from StringUtil of PropertyAccess) | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | no | Fixed tickets | N/A | License | MIT | Doc PR | N/A As proposed by @dunglas here: #18166 (comment) This will help us fix #18166 Commits ------- 8abebf6 Add Inflector component (from StringUtil of PropertyAccess)
Is/can this component be used for #18149 ? |
…glas) This PR was squashed before being merged into the 3.2-dev branch (closes #18337). Discussion ---------- [PropertyInfo] Support singular adder and remover | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18166 | License | MIT | Doc PR | n/a Fix #18166 with only a soft dependency to the PropertyAccess component. If #18260 is accepted, this PR can be reworked to use this new component, in the meantime it fixes the problem with a soft dependency. I don't now if it should be considered as a bug fix (and then merged in 2.8) or as a new feature. It's technically a bug fix but I'm not sure that introducing a new soft dependency is acceptable if older branches. What do you think @symfony/deciders? Commits ------- 4cbb60c [PropertyInfo] Support singular adder and remover
…class (xabbuh) This PR was merged into the 3.2 branch. Discussion ---------- [PropertyAccess] document deprecation of the StringUtil class | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18260 | License | MIT | Doc PR | Commits ------- f00c47a document deprecation of the StringUtil class
As proposed by @dunglas here: #18166 (comment)
This will help us fix #18166