Skip to content

[HttpFoundation] deprecate HeaderBag::get() returning an array and add all($key) instead #32122

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

Simperfit
Copy link
Contributor

@Simperfit Simperfit commented Jun 20, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? maybe
Tests pass? yes
Fixed tickets #31317
License MIT
Doc PR todo

the $first param has been deprecated in the get methid
and we are adding a $key parameter to all to get all values from a key as arrays
Do we deprecated the get method ? if so this will be a little bigger in terms of changes.

@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch from e9544ef to fad5ccb Compare June 20, 2019 20:01
Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

given now all() vs getAll() ... im wondering if getValue() / getValues() is the better name

overall 👍 for the intent

@Simperfit Simperfit requested a review from dunglas as a code owner June 23, 2019 13:41
@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch 2 times, most recently from 768bfef to 3b7af3a Compare June 23, 2019 14:09
@nicolas-grekas nicolas-grekas added this to the next milestone Jun 23, 2019
@Simperfit
Copy link
Contributor Author

Maybe we should introduced the method firstly and then deprecate the get and remove the usage, because like this it would be hard to do both in the same PR. cc @ro0NL

@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch 3 times, most recently from bf8c439 to 63a4a2d Compare June 27, 2019 06:47
@fabpot
Copy link
Member

fabpot commented Jun 27, 2019

I'm against deprecating get(). It's one a those function used a lot. We can deprecate the second argument and create a new method for getting all values though.

@Simperfit
Copy link
Contributor Author

So getValue becames get and we keep getValues.
I think it's ok too because get is used everywhere in the code base and in project too.

@fabpot
Copy link
Member

fabpot commented Jun 27, 2019

To be honest, I would prefer to not change anything :)

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

I'd like some other opinion here @symfony/deciders

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 8, 2019

I'm for keeping get() and make it always return a string (ie deprecate argument $first) and adding getAll($key): array

@lyrixx
Copy link
Member

lyrixx commented Jul 8, 2019

Same opinion as @nicolas-grekas

@fabpot fabpot closed this Jul 8, 2019
@fabpot fabpot reopened this Jul 8, 2019
@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch from 63a4a2d to f8d3ffa Compare July 8, 2019 16:19
@Simperfit
Copy link
Contributor Author

PR Updated

@Tobion
Copy link
Contributor

Tobion commented Jul 8, 2019

I also think we should give set the same treatment as get to be consistent and make it use real types.

@Simperfit Simperfit changed the title [HttpFoundation] add HeaderBag::getFirst and HeaderBag::getAll [HttpFoundation] deprecating HeaderBag::get returning an array and add HeaderBag::getValues Jul 11, 2019
@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch from f8d3ffa to d47783a Compare July 11, 2019 04:11
@Simperfit Simperfit changed the title [HttpFoundation] deprecating HeaderBag::get returning an array and add HeaderBag::getValues [HttpFoundation] deprecating HeaderBag::get/set getting/returning an array and add HeaderBag::getValues/setValues Jul 11, 2019
@Simperfit
Copy link
Contributor Author

@Tobion updated

@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch 2 times, most recently from aedda78 to 00bdb70 Compare July 31, 2019 05:52
@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch from 00bdb70 to d0cc721 Compare July 31, 2019 05:58
if (1 <= \func_num_args() && null !== $key = func_get_arg(0)) {
$key = str_replace('_', '-', strtolower($key));

return $this->headers[$key] ?? [];
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't solve the problem in the linked issue (the get method having 2 different return types depending on a parameter), now it's all that can return either string[] or string[][] based on the presence of a parameter.

Copy link
Member

@nicolas-grekas nicolas-grekas Aug 6, 2019

Choose a reason for hiding this comment

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

that's fine to me, the proposed interface is a nice and consistent update

@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch from d0cc721 to dba2c3f Compare August 6, 2019 11:30
@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] deprecating HeaderBag::get getting an array and add a param to all() to return all values [HttpFoundation] deprecate HeaderBag::get() returning an array and add all($name) instead Aug 6, 2019
@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] deprecate HeaderBag::get() returning an array and add all($name) instead [HttpFoundation] deprecate HeaderBag::get() returning an array and add all($key) instead Aug 6, 2019
@Simperfit Simperfit force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch 2 times, most recently from c166e23 to d544054 Compare August 6, 2019 12:14
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I'm adding the missing UPGRADE/CHANGELOG lines.

@nicolas-grekas nicolas-grekas force-pushed the feature/add-getFirst-and-getAll-to-not-do-both-on-get branch from d544054 to 2c5a8f1 Compare August 8, 2019 18:15
@nicolas-grekas
Copy link
Member

Thank you @Simperfit.

@nicolas-grekas nicolas-grekas merged commit 2c5a8f1 into symfony:4.4 Aug 8, 2019
nicolas-grekas added a commit that referenced this pull request Aug 8, 2019
…an array and add all($key) instead (Simperfit)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpFoundation] deprecate HeaderBag::get() returning an array and add all($key) instead

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | maybe <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #31317  <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | todo <!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

the $first param has been deprecated in the get methid
and we are adding a $key parameter to all to get all values from a key as arrays
Do we deprecated the get method ? if so this will be a little bigger in terms of changes.

Commits
-------

2c5a8f1 [HttpFoundation] deprecate using $first in get and added key in all
* @return array An array of headers
*/
public function all()
public function all(/*string $key = null*/)
Copy link
Contributor

Choose a reason for hiding this comment

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

That is a no-go for me. It introduces another of #31317 which this PR tried to fix.
Depending on the arguments it returns an array of arrays or an array of strings.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's the same as on the Messenger Envelope but that was on my todo to fix as was a pain to work with.

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.

9 participants