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

Skip to content

Commit 831c006

Browse files
committed
Deprecate SessonHanderProxy
Signed-off-by: Alexandru Furculita <[email protected]>
1 parent 73a1235 commit 831c006

16 files changed

+42
-95
lines changed

UPGRADE-3.4.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,13 @@ HttpFoundation
212212
class has been deprecated and will be removed in 4.0. Use the `\SessionHandler` class instead.
213213

214214
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy` class has been
215-
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
216-
class instead.
215+
deprecated and will be removed in 4.0. Use your `\SessionHandlerInterface` implementation directly.
217216

218217
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` class has been
219-
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
220-
class instead.
218+
deprecated and will be removed in 4.0. Use your `\SessionHandlerInterface` implementation directly.
221219

222-
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isSessionHandlerInterface()`
223-
method has been deprecated and will be removed in 4.0.
224-
225-
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isWrapper()`
226-
method has been deprecated and will be removed in 4.0. You can check explicitly if the proxy wraps
227-
a `\SessionHandler` instance.
220+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy` class has been
221+
deprecated and will be removed in 4.0. Use your `\SessionHandlerInterface` implementation directly.
228222

229223
* `NativeSessionStorage::setSaveHandler()` now takes an instance of `\SessionHandlerInterface` as argument.
230224
Not passing it is deprecated and will throw a `TypeError` in 4.0.

UPGRADE-4.0.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,9 @@ HttpFoundation
525525
not supported anymore, use `Request::isMethodCacheable()` instead.
526526

527527
* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`,
528-
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy` and
529-
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` classes have been removed.
530-
531-
* The `SessionHandlerProxy::isSessionHandlerInterface()` and `SessionHandlerProxy::isWrapper()`
532-
methods have been removed.
528+
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy`,
529+
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` and
530+
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy` classes have been removed.
533531

534532
* `NativeSessionStorage::setSaveHandler()` now requires an instance of `\SessionHandlerInterface` as argument.
535533

src/Symfony/Bridge/Twig/Tests/AppVariableTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public function testEnvironment()
4747

4848
public function testGetSession()
4949
{
50+
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
5051
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
51-
$request->method('getSession')->willReturn($session = new Session());
52+
$request->method('getSession')->willReturn($session);
5253

5354
$this->setRequestStack($request);
5455

@@ -167,8 +168,9 @@ public function testGetFlashesWithNoRequest()
167168

168169
public function testGetFlashesWithNoSessionStarted()
169170
{
171+
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
170172
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
171-
$request->method('getSession')->willReturn(new Session());
173+
$request->method('getSession')->willReturn($session);
172174

173175
$this->setRequestStack($request);
174176

@@ -257,7 +259,7 @@ private function setFlashMessages()
257259
$flashBag = new FlashBag();
258260
$flashBag->initialize($flashMessages);
259261

260-
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->getMock();
262+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->disableOriginalConstructor()->getMock();
261263
$session->method('isStarted')->willReturn(true);
262264
$session->method('getFlashBag')->willReturn($flashBag);
263265

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function testRedirectToRoute()
376376
public function testAddFlash()
377377
{
378378
$flashBag = new FlashBag();
379-
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->getMock();
379+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->disableOriginalConstructor()->getMock();
380380
$session->expects($this->once())->method('getFlashBag')->willReturn($flashBag);
381381

382382
$container = new Container();

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated the `NativeSessionHandler` class,
8-
* deprecated the `AbstractProxy` and `NativeProxy` classes in favor of `SessionHandlerProxy` class,
9-
* deprecated the `SessionHandlerProxy::isSessionHandlerInterface()` and `SessionHandlerProxy::isWrapper()` methods,
8+
* deprecated the `AbstractProxy`, `NativeProxy` and `SessionHandlerProxy` classes,
109
* deprecated setting session save handlers that do not implement `\SessionHandlerInterface` in `NativeSessionStorage::setSaveHandler()`
1110

1211
3.3.0

src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class MetadataBag implements SessionBagInterface
5454
private $updateThreshold;
5555

5656
/**
57-
* Constructor.
58-
*
5957
* @param string $storageKey The key used to store bag in the session
6058
* @param int $updateThreshold The time to wait between two UPDATED updates
6159
*/

src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class MockArraySessionStorage implements SessionStorageInterface
6363
protected $bags = array();
6464

6565
/**
66-
* Constructor.
67-
*
6866
* @param string $name Session name
6967
* @param MetadataBag $metaBag MetadataBag instance
7068
*/

src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class MockFileSessionStorage extends MockArraySessionStorage
3030
private $savePath;
3131

3232
/**
33-
* Constructor.
34-
*
3533
* @param string $savePath Path of directory to save session files
3634
* @param string $name Session name
3735
* @param MetadataBag $metaBag MetadataBag instance

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
class NativeSessionStorage implements SessionStorageInterface
2525
{
2626
/**
27-
* Array of SessionBagInterface.
28-
*
2927
* @var SessionBagInterface[]
3028
*/
3129
protected $bags;
@@ -51,8 +49,6 @@ class NativeSessionStorage implements SessionStorageInterface
5149
protected $metadataBag;
5250

5351
/**
54-
* Constructor.
55-
*
5652
* Depending on how you want the storage driver to behave you probably
5753
* want to override this constructor entirely.
5854
*
@@ -378,6 +374,13 @@ public function setSaveHandler($saveHandler = null)
378374
throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.');
379375
}
380376

377+
if ($saveHandler instanceof AbstractProxy) {
378+
@trigger_error(
379+
'Using session save handlers that are instances of AbstractProxy is deprecated since version 3.4 and will be removed in 4.0.',
380+
E_USER_DEPRECATED
381+
);
382+
}
383+
381384
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
382385
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
383386
$saveHandler = new SessionHandlerProxy($saveHandler);
@@ -388,8 +391,6 @@ public function setSaveHandler($saveHandler = null)
388391

389392
if ($this->saveHandler instanceof \SessionHandlerInterface) {
390393
session_set_save_handler($this->saveHandler, false);
391-
} else {
392-
@trigger_error('Using session save handlers that do not implement \SessionHandlerInterface is deprecated since version 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
393394
}
394395
}
395396

src/Symfony/Component/HttpFoundation/Session/Storage/PhpBridgeSessionStorage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
class PhpBridgeSessionStorage extends NativeSessionStorage
2222
{
2323
/**
24-
* Constructor.
25-
*
2624
* @param AbstractProxy|\SessionHandlerInterface|null $handler
2725
* @param MetadataBag $metaBag MetadataBag
2826
*/

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\AbstractProxy class is deprecated since version 3.4 and will be removed in 4.0. Use your session handler implementation directly.', E_USER_DEPRECATED);
15+
1416
/**
15-
* @deprecated since version 3.4, to be removed in 4.0. Use SessionHandlerProxy instead.
17+
* @deprecated since version 3.4, to be removed in 4.0. Use your session handler implementation directly.
1618
*
1719
* @author Drak <[email protected]>
1820
*/
@@ -21,8 +23,6 @@ abstract class AbstractProxy
2123
/**
2224
* Flag if handler wraps an internal PHP session handler (using \SessionHandler).
2325
*
24-
* @deprecated since version 3.4 and will be removed in 4.0.
25-
*
2626
* @var bool
2727
*/
2828
protected $wrapper = false;
@@ -45,28 +45,20 @@ public function getSaveHandlerName()
4545
/**
4646
* Is this proxy handler and instance of \SessionHandlerInterface.
4747
*
48-
* @deprecated since version 3.4 and will be removed in 4.0.
49-
*
5048
* @return bool
5149
*/
5250
public function isSessionHandlerInterface()
5351
{
54-
@trigger_error('isSessionHandlerInterface() is deprecated since version 3.4 and will be removed in 4.0. A session handler proxy should always implement \SessionHandlerInterface.', E_USER_DEPRECATED);
55-
5652
return $this instanceof \SessionHandlerInterface;
5753
}
5854

5955
/**
6056
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
6157
*
62-
* @deprecated since version 3.4 and will be removed in 4.0.
63-
*
6458
* @return bool
6559
*/
6660
public function isWrapper()
6761
{
68-
@trigger_error('isWrapper() is deprecated since version 3.4 and will be removed in 4.0. You should explicitly check if the handler proxy wraps a \SessionHandler instance.', E_USER_DEPRECATED);
69-
7062
return $this->wrapper;
7163
}
7264

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/NativeProxy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14-
@trigger_error('The '.__NAMESPACE__.'\NativeProxy class is deprecated since version 3.4 and will be removed in 4.0. Use the Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy class instead.', E_USER_DEPRECATED);
14+
@trigger_error('The '.__NAMESPACE__.'\NativeProxy class is deprecated since version 3.4 and will be removed in 4.0. Use your session handler implementation directly.', E_USER_DEPRECATED);
1515

1616
/**
1717
* This proxy is built-in session handlers in PHP 5.3.x.
1818
*
19-
* @deprecated since version 3.4, to be removed in 4.0. Use SessionHandlerProxy instead.
19+
* @deprecated since version 3.4, to be removed in 4.0. Use your session handler implementation directly.
2020
*
2121
* @author Drak <[email protected]>
2222
*/

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\SessionHandlerProxy class is deprecated since version 3.4 and will be removed in 4.0. Use your session handler implementation directly.', E_USER_DEPRECATED);
15+
1416
/**
17+
* @deprecated since version 3.4, to be removed in 4.0. Use your session handler implementation directly.
18+
*
1519
* @author Drak <[email protected]>
1620
*/
1721
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,17 @@ public function testSetSaveHandler()
198198
$this->iniSet('session.save_handler', 'files');
199199
$storage = $this->getStorage();
200200
$storage->setSaveHandler();
201-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
201+
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
202202
$storage->setSaveHandler(null);
203-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
203+
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
204204
$storage->setSaveHandler(new SessionHandlerProxy(new NativeSessionHandler()));
205-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
205+
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
206206
$storage->setSaveHandler(new NativeSessionHandler());
207-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
207+
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
208208
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
209-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
209+
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
210210
$storage->setSaveHandler(new NullSessionHandler());
211-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
211+
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
212212
}
213213

214214
/**

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,13 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
16-
17-
// Note until PHPUnit_Mock_Objects 1.2 is released you cannot mock abstracts due to
18-
// https://github.com/sebastianbergmann/phpunit-mock-objects/issues/73
19-
class ConcreteProxy extends AbstractProxy
20-
{
21-
}
22-
23-
class ConcreteSessionHandlerInterfaceProxy extends AbstractProxy implements \SessionHandlerInterface
24-
{
25-
public function open($savePath, $sessionName)
26-
{
27-
}
28-
29-
public function close()
30-
{
31-
}
32-
33-
public function read($id)
34-
{
35-
}
36-
37-
public function write($id, $data)
38-
{
39-
}
40-
41-
public function destroy($id)
42-
{
43-
}
44-
45-
public function gc($maxlifetime)
46-
{
47-
}
48-
}
16+
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
4917

5018
/**
5119
* Test class for AbstractProxy.
5220
*
21+
* @group legacy
22+
*
5323
* @author Drak <[email protected]>
5424
*/
5525
class AbstractProxyTest extends TestCase
@@ -61,7 +31,7 @@ class AbstractProxyTest extends TestCase
6131

6232
protected function setUp()
6333
{
64-
$this->proxy = new ConcreteProxy();
34+
$this->proxy = $this->getMockForAbstractClass(AbstractProxy::class);
6535
}
6636

6737
protected function tearDown()
@@ -74,19 +44,13 @@ public function testGetSaveHandlerName()
7444
$this->assertNull($this->proxy->getSaveHandlerName());
7545
}
7646

77-
/**
78-
* @group legacy
79-
*/
8047
public function testIsSessionHandlerInterface()
8148
{
8249
$this->assertFalse($this->proxy->isSessionHandlerInterface());
83-
$sh = new ConcreteSessionHandlerInterfaceProxy();
50+
$sh = new SessionHandlerProxy(new \SessionHandler());
8451
$this->assertTrue($sh->isSessionHandlerInterface());
8552
}
8653

87-
/**
88-
* @group legacy
89-
*/
9054
public function testIsWrapper()
9155
{
9256
$this->assertFalse($this->proxy->isWrapper());

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*
2222
* @runTestsInSeparateProcesses
2323
* @preserveGlobalState disabled
24+
* @group legacy
2425
*/
2526
class SessionHandlerProxyTest extends TestCase
2627
{

0 commit comments

Comments
 (0)