You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description Cookie class is immutable and thus its settings can be set only during construction via constructor or static create method. Both methods accept 1 required argument (which is cookie name) and 8 optional arguments.
Most of the time, I don't need httpOnly flag which makes me specify 7 arguments almost every time I wanna create a cookie :-) Setters can bring much more effort (IMO. see example below). Setting sameSite will require me to specify all 9 previous arguments.
Since now only cookie name is required we can avoid BC by moving validation logic into setters and calling them from the constructor.
Example
For now, I create a cookie like this (I specify 7 arguments 'cause I wanna disable httpOnly):
I'm stuck to a similar problem, I get my cookie from a external service after an http request and I need to set the domain to an other value so the easy way could be
This PR was squashed before being merged into the 5.1-dev branch (closes#35215).
Discussion
----------
[HttpFoundation] added withers to Cookie class
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fix#35212
| License | MIT
| Doc PR | -
I was quite descriptive in the issue :-)
The main idea is to get the interface for changing a cookie to avoid every unneeded argument in the constructor.
Current:
```php
$cookie = Cookie::create(
RegionSwitcher::REGION_COOKIE, $regionSlug, new DateTime('+1 year'), '/',
$baseDomain, null, false
);
```
This PR:
```php
$cookie = Cookie::create('foo')
->withValue('bar')
->withExpiresTime(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
->withDomain('.myfoodomain.com')
->withSecure(true);
```
Every `wither` returns a copy of current cookie with requested setting set. Cookie class remains immutable.
Commits
-------
549afaa [HttpFoundation] added withers to Cookie class
Uh oh!
There was an error while loading. Please reload this page.
Description
Cookie class is immutable and thus its settings can be set only during construction via constructor or static
create
method. Both methods accept 1 required argument (which is cookie name) and 8 optional arguments.Most of the time, I don't need
httpOnly
flag which makes me specify 7 arguments almost every time I wanna create a cookie :-) Setters can bring much more effort (IMO. see example below). SettingsameSite
will require me to specify all 9 previous arguments.Since now only cookie name is required we can avoid BC by moving validation logic into setters and calling them from the constructor.
Example
For now, I create a cookie like this (I specify 7 arguments 'cause I wanna disable
httpOnly
):With setters, I can only call 4 methods which looks much nicer to me:
I can make a PR if accepted. Thanks in advance!
The text was updated successfully, but these errors were encountered: