Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 729ead4

Browse files
committed
Remove the default values from setters with a nullable parameter.
1 parent 57e39b4 commit 729ead4

File tree

11 files changed

+128
-3
lines changed

11 files changed

+128
-3
lines changed

UPGRADE-5.3.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
UPGRADE FROM 5.2 to 5.3
2+
=======================
3+
4+
DependencyInjection
5+
-------------------
6+
7+
* The signature of `ContainerAwareInterface::setContainer()` has been updated to `setContainer(?ContainerInterface $container)`. When calling an implementation of this interface, explicitly pass `null` if you want to unset the container.
8+
* Calling `ContainerAwareTrait::setContainer()` without arguments is deprecated. Please explicitly pass `null` if you want to unset the container.
9+
10+
Security
11+
-------------------
12+
13+
* The signature of `TokenStorageInterface::setToken()` has been updated to `setToken(?TokenInterface $token)`. When calling an implementation of this interface, explicitly pass `null` if you want to unset the token.
14+
* Calling `TokenStorage::setToken()` or `UsageTrackingTokenStorage::setToken()` without arguments is deprecated. Please explicitly pass `null` if you want to unset the token.

UPGRADE-6.0.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ DependencyInjection
2626
* Removed `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead.
2727
* The `inline()` function from the PHP-DSL has been removed, use `inline_service()` instead.
2828
* The `ref()` function from the PHP-DSL has been removed, use `service()` instead.
29-
* Removed `Definition::setPrivate()` and `Alias::setPrivate()`, use `setPublic()` instead
29+
* Removed `Definition::setPrivate()` and `Alias::setPrivate()`, use `setPublic()` instead.
30+
* The signatures of `ContainerAwareInterface::setContainer()` and `ContainerAwareTrait::setContainer()` have been updated to `setContainer(?ContainerInterface $container)`. When calling an implementation of this interface, explicitly pass `null` if you want to unset the container.
3031

3132
Dotenv
3233
------
@@ -153,6 +154,7 @@ Security
153154
in `PreAuthenticatedToken`, `RememberMeToken`, `SwitchUserToken`, `UsernamePasswordToken`,
154155
`DefaultAuthenticationSuccessHandler`.
155156
* Removed the `AbstractRememberMeServices::$providerKey` property in favor of `AbstractRememberMeServices::$firewallName`
157+
* The signatures of `TokenStorageInterface::setToken()`, `TokenStorage::setToken()` and `UsageTrackingTokenStorage::setToken()` have been updated to `setToken(?TokenInterface $token)`. When calling an implementation of this interface, explicitly pass `null` if you want to unset the token.
156158

157159
TwigBundle
158160
----------

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* changed the signature of `ContainerAwareInterface::setContainer()` to `setContainer(?ContainerInterface $container)`
8+
* deprecated calling `ContainerAwareTrait::setContainer()` without arguments
9+
410
5.2.0
511
-----
612

src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ interface ContainerAwareInterface
2121
/**
2222
* Sets the container.
2323
*/
24-
public function setContainer(ContainerInterface $container = null);
24+
public function setContainer(?ContainerInterface $container);
2525
}

src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ trait ContainerAwareTrait
2525

2626
public function setContainer(ContainerInterface $container = null)
2727
{
28+
if (1 > \func_num_args()) {
29+
trigger_deprecation('symfony/dependency-injection', '5.3', 'Calling "%s::%s" without any arguments is deprecated. Please explicitly pass null if you want to unset the container.', static::class, __FUNCTION__);
30+
}
31+
2832
$this->container = $container;
2933
}
3034
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
16+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
17+
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
18+
use Symfony\Component\DependencyInjection\ContainerInterface;
19+
20+
class ContainerAwareTraitTest extends TestCase
21+
{
22+
use ExpectDeprecationTrait;
23+
24+
/**
25+
* @group legacy
26+
*/
27+
public function testSetContainerLegacy()
28+
{
29+
$container = $this->createMock(ContainerInterface::class);
30+
31+
$dummy = new ContainerAwareDummy();
32+
$dummy->setContainer($container);
33+
34+
self::assertSame($container, $dummy->getContainer());
35+
36+
$this->expectDeprecation('Since symfony/dependency-injection 5.3: Calling "Symfony\Component\DependencyInjection\Tests\ContainerAwareDummy::setContainer" without any arguments is deprecated. Please explicitly pass null if you want to unset the container.');
37+
38+
$dummy->setContainer();
39+
self::assertNull($dummy->getContainer());
40+
}
41+
42+
public function testSetContainer()
43+
{
44+
$container = $this->createMock(ContainerInterface::class);
45+
46+
$dummy = new ContainerAwareDummy();
47+
$dummy->setContainer($container);
48+
49+
self::assertSame($container, $dummy->getContainer());
50+
51+
$dummy->setContainer(null);
52+
self::assertNull($dummy->getContainer());
53+
}
54+
}
55+
56+
class ContainerAwareDummy implements ContainerAwareInterface
57+
{
58+
use ContainerAwareTrait;
59+
60+
public function getContainer(): ?ContainerInterface
61+
{
62+
return $this->container;
63+
}
64+
}

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* Changed the signature of `TokenStorageInterface::setToken()` to `setToken(?TokenInterface $token)`
8+
* Deprecated calling `TokenStorage::setToken()` or `UsageTrackingTokenStorage::setToken()` without arguments
9+
410
5.2.0
511
-----
612

src/Symfony/Component/Security/Core/Authentication/Token/Storage/TokenStorage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function getToken()
4545
*/
4646
public function setToken(TokenInterface $token = null)
4747
{
48+
if (1 > \func_num_args()) {
49+
trigger_deprecation('symfony/security-core', '5.3', 'Calling "%s" without any arguments is deprecated. Please explicitly pass null if you want to unset the token.', __METHOD__);
50+
}
51+
4852
if ($token) {
4953
// ensure any initializer is called
5054
$this->getToken();

src/Symfony/Component/Security/Core/Authentication/Token/Storage/TokenStorageInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ public function getToken();
3232
*
3333
* @param TokenInterface $token A TokenInterface token, or null if no further authentication information should be stored
3434
*/
35-
public function setToken(TokenInterface $token = null);
35+
public function setToken(?TokenInterface $token);
3636
}

src/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function getToken(): ?TokenInterface
5151
*/
5252
public function setToken(TokenInterface $token = null): void
5353
{
54+
if (1 > \func_num_args()) {
55+
trigger_deprecation('symfony/security-core', '5.3', 'Calling "%s" without any arguments is deprecated. Please explicitly pass null if you want to unset the token.', __METHOD__);
56+
}
57+
5458
$this->storage->setToken($token);
5559

5660
if ($token && $this->enableUsageTracking) {

0 commit comments

Comments
 (0)