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

Skip to content

Commit 4683915

Browse files
author
Drak
committed
[HttpFoundation] Free bags from session storage and move classes to their own namespaces.
1 parent d64939a commit 4683915

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+385
-383
lines changed

CHANGELOG-2.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
232232
* Flashes are now stored as a bucket of messages per `$type` so there can be multiple messages per type.
233233
There are four interface constants for type, `FlashBagInterface::INFO`, `FlashBagInterface::NOTICE`,
234234
`FlashBagInterface::WARNING` and `FlashBagInterface::ERROR`.
235-
* Added `FlashBag` (default). Flashes expire when retrieved by `popFlashes()`.
235+
* Added `FlashBag` (default). Flashes expire when retrieved by `pop()` or `popAll()`.
236236
This makes the implementation ESI compatible.
237237
* Added `AutoExpireFlashBag` to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring
238238
after one page page load. Messages must be retrived by `pop()` or `popAll()`.

UPGRADE-2.1.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ UPGRADE FROM 2.0 to 2.1
259259
</div>
260260
<?php endif; ?>
261261

262-
If You wanted to process all flash types you could also make use of the `popAllFlashes()` API:
262+
If you wanted to process all flash types you could also make use of the `getFlashes()->all()` API:
263263

264264
<?php foreach ($view['session']->getFlashes()->all() as $type => $flash): ?>
265265
<div class="flash-$type">
@@ -270,8 +270,8 @@ UPGRADE FROM 2.0 to 2.1
270270
.. note::
271271

272272
The Flash Message API provides constants which you can optionally use. For example
273-
`Symfony\Component\HttpFoundation\FlashBag::NOTICE`, which can also be abbreviated to
274-
`FlashBag::NOTICE` providing you declare `<?php use Symfony\Component\HttpFoundation\FlashBag; ?>`
273+
`Symfony\Component\HttpFoundation\SessionFlash\FlashBag::NOTICE`, which can also be abbreviated to
274+
`FlashBag::NOTICE` providing you declare `<?php use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; ?>`
275275
at the beginning of the PHP template.
276276

277277
Before (Twig):
@@ -301,7 +301,7 @@ UPGRADE FROM 2.0 to 2.1
301301
.. note::
302302

303303
You can optionally use constants in Twig templates using `constant()` e.g.
304-
`constant('Symfony\Component\HttpFoundation\FlashBag::NOTICE')`.
304+
`constant('Symfony\Component\HttpFoundation\SessionFlash\FlashBag::NOTICE')`.
305305

306306
* Session object
307307

src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Symfony\Bridge\Doctrine\HttpFoundation;
44

55
use Doctrine\DBAL\Platforms\MySqlPlatform;
6-
use Symfony\Component\HttpFoundation\AttributeBagInterface;
7-
use Symfony\Component\HttpFoundation\FlashBagInterface;
86
use Symfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage;
97
use Symfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface;
108
use Doctrine\DBAL\Driver\Connection;
@@ -32,15 +30,13 @@ class DbalSessionStorage extends AbstractSessionStorage implements SessionSaveHa
3230
* @param Connection $con An instance of Connection.
3331
* @param string $tableName Table name.
3432
* @param array $options Session configuration options
35-
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
36-
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
3733
*/
38-
public function __construct(Connection $con, $tableName = 'sessions', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
34+
public function __construct(Connection $con, $tableName = 'sessions', array $options = array())
3935
{
4036
$this->con = $con;
4137
$this->tableName = $tableName;
4238

43-
parent::__construct($attributes, $flashes, $options);
39+
parent::__construct($options);
4440
}
4541

4642
/**

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
<parameters>
88
<parameter key="session.class">Symfony\Component\HttpFoundation\Session</parameter>
9-
<parameter key="session.flashbag.class">Symfony\Component\HttpFoundation\FlashBag</parameter>
10-
<parameter key="session.attribute_bag.class">Symfony\Component\HttpFoundation\AttributeBag</parameter>
9+
<parameter key="session.flashbag.class">Symfony\Component\HttpFoundation\SessionFlash\FlashBag</parameter>
10+
<parameter key="session.attribute_bag.class">Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag</parameter>
1111
<parameter key="session.storage.native_file.class">Symfony\Component\HttpFoundation\SessionStorage\NativeFileSessionStorage</parameter>
1212
<parameter key="session.storage.null.class">Symfony\Component\HttpFoundation\SessionStorage\NullSessionStorage</parameter>
1313
<parameter key="session.storage.native_memcache.class">Symfony\Component\HttpFoundation\SessionStorage\NativeMemcacheSessionStorage</parameter>
@@ -25,6 +25,8 @@
2525
<services>
2626
<service id="session" class="%session.class%">
2727
<argument type="service" id="session.storage" />
28+
<argument type="service" id="session.attribute_bag" />
29+
<argument type="service" id="session.flash_bag" />
2830
</service>
2931

3032
<service id="session.flash_bag" class="%session.flashbag.class%" public="false" />
@@ -35,58 +37,42 @@
3537
<service id="session.storage.mock_file" class="%session.storage.mock_file.class%" public="false">
3638
<argument>%kernel.cache_dir%/sessions</argument>
3739
<argument>%session.storage.options%</argument>
38-
<argument type="service" id="session.attribute_bag" />
39-
<argument type="service" id="session.flash_bag" />
4040
</service>
4141

4242
<service id="session.storage.native_file" class="%session.storage.native_file.class%" public="false">
4343
<argument>%kernel.cache_dir%/sessions</argument>
4444
<argument>%session.storage.options%</argument>
45-
<argument type="service" id="session.attribute_bag" />
46-
<argument type="service" id="session.flash_bag" />
4745
</service>
4846

4947
<service id="session.storage.native_memcache" class="%session.storage.native_memcache.class%" public="false">
5048
<argument>tcp://127.0.0.1:11211?persistent=0</argument>
5149
<argument>%session.storage.options%</argument>
52-
<argument type="service" id="session.attribute_bag" />
53-
<argument type="service" id="session.flash_bag" />
5450
</service>
5551

5652
<service id="session.storage.native_memcached" class="%session.storage.native_memcached.class%" public="false">
5753
<argument>127.0.0.1:11211</argument>
5854
<argument>%session.storage.options%</argument>
59-
<argument type="service" id="session.attribute_bag" />
60-
<argument type="service" id="session.flash_bag" />
6155
</service>
6256

6357
<service id="session.storage.memcache" class="%session.storage.memcache.class%" public="false">
6458
<argument type="service" id="session.memcache" />
6559
<argument>tcp://127.0.0.1:11211?persistent=0</argument>
6660
<argument>%session.storage.options%</argument>
67-
<argument type="service" id="session.attribute_bag" />
68-
<argument type="service" id="session.flash_bag" />
6961
</service>
7062

7163
<service id="session.storage.memcached" class="%session.storage.memcached.class%" public="false">
7264
<argument type="service" id="session.memcached" />
7365
<argument>tcp://127.0.0.1:11211?persistent=0</argument>
7466
<argument>%session.storage.options%</argument>
75-
<argument type="service" id="session.attribute_bag" />
76-
<argument type="service" id="session.flash_bag" />
7767
</service>
7868

7969
<service id="session.storage.native_sqlite" class="%session.storage.native_sqlite.class%" public="false">
8070
<argument>%kernel.cache_dir%/sf2_sqlite_sess.db</argument>
8171
<argument>%session.storage.options%</argument>
82-
<argument type="service" id="session.attribute_bag" />
83-
<argument type="service" id="session.flash_bag" />
8472
</service>
8573

8674
<service id="session.storage.null" class="%session.storage.null.class%" public="false">
8775
<argument>%session.storage.options%</argument>
88-
<argument type="service" id="session.attribute_bag" />
89-
<argument type="service" id="session.flash_bag" />
9076
</service>
9177

9278
<service id="session_listener" class="%session_listener.class%">

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Templating\Helper\Helper;
1515
use Symfony\Component\HttpFoundation\Request;
16-
use Symfony\Component\HttpFoundation\FlashBagInterface;
16+
use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
1717

1818
/**
1919
* SessionHelper provides read-only access to the session attributes.

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use Symfony\Component\HttpFoundation\Session;
1616
use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage;
1717
use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper;
18-
use Symfony\Component\HttpFoundation\FlashBag;
19-
use Symfony\Component\HttpFoundation\AttributeBag;
18+
use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
19+
use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
2020

2121
class SessionHelperTest extends \PHPUnit_Framework_TestCase
2222
{

src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\HttpKernel\HttpKernelInterface;
1616
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
1717
use Symfony\Bundle\TwigBundle\TwigEngine;
18-
use Symfony\Component\HttpFoundation\AutoExpireFlashBag;
18+
use Symfony\Component\HttpFoundation\SessionFlash\AutoExpireFlashBag;
1919

2020
/**
2121
* WebDebugToolbarListener injects the Web Debug Toolbar.

src/Symfony/Component/HttpFoundation/AttributeBagInterface.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Symfony/Component/HttpFoundation/Session.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
namespace Symfony\Component\HttpFoundation;
1313

1414
use Symfony\Component\HttpFoundation\SessionStorage\SessionStorageInterface;
15-
use Symfony\Component\HttpFoundation\FlashBagInterface;
15+
use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
16+
use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBagInterface;
17+
use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
18+
use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
19+
use Symfony\Component\HttpFoundation\SessionBagInterface;
1620

1721
/**
1822
* Session.
@@ -35,10 +39,14 @@ class Session implements SessionInterface
3539
* Constructor.
3640
*
3741
* @param SessionStorageInterface $storage A SessionStorageInterface instance.
42+
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
43+
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
3844
*/
39-
public function __construct(SessionStorageInterface $storage)
45+
public function __construct(SessionStorageInterface $storage, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
4046
{
4147
$this->storage = $storage;
48+
$this->registerBag($attributes ?: new AttributeBag());
49+
$this->registerBag($flashes ?: new FlashBag());
4250
}
4351

4452
/**
@@ -64,7 +72,7 @@ public function start()
6472
*/
6573
public function has($name)
6674
{
67-
return $this->storage->getAttributes()->has($name);
75+
return $this->storage->getBag('attributes')->has($name);
6876
}
6977

7078
/**
@@ -79,7 +87,7 @@ public function has($name)
7987
*/
8088
public function get($name, $default = null)
8189
{
82-
return $this->storage->getAttributes()->get($name, $default);
90+
return $this->storage->getBag('attributes')->get($name, $default);
8391
}
8492

8593
/**
@@ -92,7 +100,7 @@ public function get($name, $default = null)
92100
*/
93101
public function set($name, $value)
94102
{
95-
$this->storage->getAttributes()->set($name, $value);
103+
$this->storage->getBag('attributes')->set($name, $value);
96104
}
97105

98106
/**
@@ -104,7 +112,7 @@ public function set($name, $value)
104112
*/
105113
public function all()
106114
{
107-
return $this->storage->getAttributes()->all();
115+
return $this->storage->getBag('attributes')->all();
108116
}
109117

110118
/**
@@ -116,7 +124,7 @@ public function all()
116124
*/
117125
public function replace(array $attributes)
118126
{
119-
$this->storage->getAttributes()->replace($attributes);
127+
$this->storage->getBag('attributes')->replace($attributes);
120128
}
121129

122130
/**
@@ -128,7 +136,7 @@ public function replace(array $attributes)
128136
*/
129137
public function remove($name)
130138
{
131-
return $this->storage->getAttributes()->remove($name);
139+
return $this->storage->getBag('attributes')->remove($name);
132140
}
133141

134142
/**
@@ -138,7 +146,7 @@ public function remove($name)
138146
*/
139147
public function clear()
140148
{
141-
$this->storage->getAttributes()->clear();
149+
$this->storage->getBag('attributes')->clear();
142150
}
143151

144152
/**
@@ -218,13 +226,23 @@ public function unserialize($serialized)
218226
$this->storage = $storage;
219227
}
220228

229+
public function registerBag(SessionBagInterface $bag)
230+
{
231+
$this->storage->registerBag($bag);
232+
}
233+
234+
public function getBag($name)
235+
{
236+
return $this->storage->getBag($name);
237+
}
238+
221239
/**
222-
* Gets all flash messages.
240+
* Gets the flashbag interface.
223241
*
224242
* @return FlashBagInterface
225243
*/
226244
public function getFlashes()
227245
{
228-
return $this->storage->getFlashes();
246+
return $this->getBag('flashes');
229247
}
230248
}

src/Symfony/Component/HttpFoundation/AttributeBag.php renamed to src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBag.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\HttpFoundation;
12+
namespace Symfony\Component\HttpFoundation\SessionAttribute;
1313

1414
/**
1515
* This class relates to session attribute storage
1616
*/
1717
class AttributeBag implements AttributeBagInterface
1818
{
19+
private $name = 'attributes';
20+
1921
/**
2022
* @var string
2123
*/
@@ -36,6 +38,19 @@ public function __construct($storageKey = '_sf2_attributes')
3638
$this->storageKey = $storageKey;
3739
}
3840

41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function getName()
45+
{
46+
return $this->name;
47+
}
48+
49+
public function setName($name)
50+
{
51+
$this->name = $name;
52+
}
53+
3954
/**
4055
* {@inheritdoc}
4156
*/
@@ -114,6 +129,9 @@ public function remove($name)
114129
*/
115130
public function clear()
116131
{
132+
$return = $this->attributes;
117133
$this->attributes = array();
134+
135+
return $return;
118136
}
119137
}

src/Symfony/Component/HttpFoundation/SessionStorage/AttributeInterface.php renamed to src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBagInterface.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\HttpFoundation\SessionStorage;
12+
namespace Symfony\Component\HttpFoundation\SessionAttribute;
13+
14+
use Symfony\Component\HttpFoundation\SessionBagInterface;
1315

1416
/**
15-
* Interface for the session.
17+
* Attributes store.
1618
*
1719
* @author Drak <[email protected]>
1820
*/
19-
interface AttributeInterface
21+
interface AttributeBagInterface extends SessionBagInterface
2022
{
2123
/**
2224
* Checks if an attribute is defined.
@@ -65,9 +67,4 @@ function replace(array $attributes);
6567
* @param string $name
6668
*/
6769
function remove($name);
68-
69-
/**
70-
* Clears all attributes.
71-
*/
72-
function clear();
7370
}

0 commit comments

Comments
 (0)