Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9133b9e

Browse filesBrowse files
committed
moved Request/Response/User classes to a new HttpFoundation component
The HttpFoundation component holds classes that wrap PHP native global arrays. The following classes has been moved: * Symfony\Components\HttpKernel\Response -> Symfony\Components\HttpFoundation\Response * Symfony\Components\HttpKernel\Request -> Symfony\Components\HttpFoundation\Request * Symfony\Framework\FoundationBundle\User -> Symfony\Components\HttpFoundation\Session * Symfony\Framework\FoundationBundle\Session\* -> Symfony\Components\HttpFoundation\SessionStorage\*Storage The web:user DI configuration has been moved to kernel:session. The user helper has been renamed to session.
1 parent e63ff6e commit 9133b9e
Copy full SHA for 9133b9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

45 files changed

+363
-279
lines changed

‎src/Symfony/Components/HttpKernel/CacheControl.php renamed to ‎src/Symfony/Components/HttpFoundation/CacheControl.php

Copy file name to clipboardExpand all lines: src/Symfony/Components/HttpFoundation/CacheControl.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Components\HttpKernel;
3+
namespace Symfony\Components\HttpFoundation;
44

55
/*
66
* This file is part of the Symfony framework.
@@ -18,7 +18,7 @@
1818
* (and those that only apply to requests or responses).
1919
*
2020
* @package Symfony
21-
* @subpackage Components_HttpKernel
21+
* @subpackage Components_HttpFoundation
2222
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2323
*/
2424
class CacheControl

‎src/Symfony/Components/HttpKernel/HeaderBag.php renamed to ‎src/Symfony/Components/HttpFoundation/HeaderBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Components/HttpFoundation/HeaderBag.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Components\HttpKernel;
3+
namespace Symfony\Components\HttpFoundation;
44

55
/*
66
* This file is part of the Symfony package.
@@ -15,7 +15,7 @@
1515
* HeaderBag is a container for HTTP headers.
1616
*
1717
* @package Symfony
18-
* @subpackage Components_HttpKernel
18+
* @subpackage Components_HttpFoundation
1919
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2020
*/
2121
class HeaderBag

‎src/Symfony/Components/HttpKernel/ParameterBag.php renamed to ‎src/Symfony/Components/HttpFoundation/ParameterBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Components/HttpFoundation/ParameterBag.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Components\HttpKernel;
3+
namespace Symfony\Components\HttpFoundation;
44

55
/*
66
* This file is part of the Symfony package.
@@ -15,7 +15,7 @@
1515
* ParameterBag is a container for key/value pairs.
1616
*
1717
* @package Symfony
18-
* @subpackage Components_HttpKernel
18+
* @subpackage Components_HttpFoundation
1919
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2020
*/
2121
class ParameterBag

‎src/Symfony/Components/HttpKernel/Request.php renamed to ‎src/Symfony/Components/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Components/HttpFoundation/Request.php
+25-2Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Symfony\Components\HttpKernel;
3+
namespace Symfony\Components\HttpFoundation;
4+
5+
use Symfony\Components\HttpFoundation\SessionStorage\NativeSessionStorage;
46

57
/*
68
* This file is part of the Symfony package.
@@ -15,7 +17,7 @@
1517
* Request represents an HTTP request.
1618
*
1719
* @package Symfony
18-
* @subpackage Components_HttpKernel
20+
* @subpackage Components_HttpFoundation
1921
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2022
*/
2123
class Request
@@ -37,6 +39,7 @@ class Request
3739
protected $basePath;
3840
protected $method;
3941
protected $format;
42+
protected $session;
4043

4144
static protected $formats;
4245

@@ -210,6 +213,26 @@ public function get($key, $default = null)
210213
return $this->query->get($key, $this->path->get($key, $this->request->get($key, $default)));
211214
}
212215

216+
public function getSession()
217+
{
218+
if (null === $this->session) {
219+
$this->session = new Session(new NativeSessionStorage());
220+
}
221+
$this->session->start();
222+
223+
return $this->session;
224+
}
225+
226+
public function hasSession()
227+
{
228+
return '' !== session_id();
229+
}
230+
231+
public function setSession(Session $session)
232+
{
233+
$this->session = $session;
234+
}
235+
213236
/**
214237
* Returns current script name.
215238
*

‎src/Symfony/Components/HttpKernel/Response.php renamed to ‎src/Symfony/Components/HttpFoundation/Response.php

Copy file name to clipboardExpand all lines: src/Symfony/Components/HttpFoundation/Response.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Components\HttpKernel;
3+
namespace Symfony\Components\HttpFoundation;
44

55
/*
66
* This file is part of the Symfony package.
@@ -15,7 +15,7 @@
1515
* Response represents an HTTP response.
1616
*
1717
* @package Symfony
18-
* @subpackage Components_HttpKernel
18+
* @subpackage Components_HttpFoundation
1919
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2020
*/
2121
class Response

‎src/Symfony/Framework/FoundationBundle/User.php renamed to ‎src/Symfony/Components/HttpFoundation/Session.php

Copy file name to clipboardExpand all lines: src/Symfony/Components/HttpFoundation/Session.php
+40-27Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22

3-
namespace Symfony\Framework\FoundationBundle;
3+
namespace Symfony\Components\HttpFoundation;
44

5-
use Symfony\Components\EventDispatcher\EventDispatcher;
6-
use Symfony\Components\EventDispatcher\Event;
7-
use Symfony\Framework\FoundationBundle\Session\SessionInterface;
5+
use Symfony\Components\HttpFoundation\SessionStorage\SessionStorageInterface;
86

97
/*
108
* This file is part of the Symfony framework.
@@ -16,42 +14,57 @@
1614
*/
1715

1816
/**
19-
* User.
17+
* Session.
2018
*
2119
* @package Symfony
2220
* @subpackage Framework_FoundationBundle
2321
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2422
*/
25-
class User
23+
class Session
2624
{
27-
protected $session;
25+
protected $storage;
2826
protected $locale;
2927
protected $attributes;
3028
protected $oldFlashes;
29+
protected $started;
30+
protected $options;
3131

3232
/**
33-
* Initialize the user class
33+
* Constructor.
3434
*
35-
* @param EventDispatcher $dispatcher A EventDispatcher instance
36-
* @param SessionInterface $session A SessionInterface instance
37-
* @param array $options An array of options
35+
* @param SessionStorageInterface $session A SessionStorageInterface instance
36+
* @param array $options An array of options
3837
*/
39-
public function __construct(EventDispatcher $dispatcher, SessionInterface $session, $options = array())
38+
public function __construct(SessionStorageInterface $storage, $options = array())
4039
{
41-
$this->dispatcher = $dispatcher;
42-
$this->session = $session;
40+
$this->storage = $storage;
41+
$this->options = $options;
42+
}
43+
44+
/**
45+
* Starts the session storage.
46+
*/
47+
public function start()
48+
{
49+
if (true === $this->started) {
50+
return;
51+
}
52+
53+
$this->storage->start();
4354

44-
$this->setAttributes($session->read('_user', array(
55+
$this->setAttributes($this->storage->read('_symfony2', array(
4556
'_flash' => array(),
46-
'_locale' => isset($options['default_locale']) ? $options['default_locale'] : 'en',
57+
'_locale' => isset($this->options['default_locale']) ? $this->options['default_locale'] : 'en',
4758
)));
4859

4960
// flag current flash to be removed at shutdown
5061
$this->oldFlashes = array_flip(array_keys($this->getFlashMessages()));
62+
63+
$this->started = true;
5164
}
5265

5366
/**
54-
* Returns a user attribute
67+
* Returns an attribute
5568
*
5669
* @param string $name The attribute name
5770
* @param mixed $default The default value
@@ -64,7 +77,7 @@ public function getAttribute($name, $default = null)
6477
}
6578

6679
/**
67-
* Sets an user attribute.
80+
* Sets an attribute.
6881
*
6982
* @param string $name
7083
* @param mixed $value
@@ -75,17 +88,17 @@ public function setAttribute($name, $value)
7588
}
7689

7790
/**
78-
* Returns user attributes
91+
* Returns attributes.
7992
*
80-
* @return array User attributes
93+
* @return array Attributes
8194
*/
8295
public function getAttributes()
8396
{
8497
return $this->attributes;
8598
}
8699

87100
/**
88-
* Sets user attributes
101+
* Sets attributes
89102
*
90103
* @param array $attributes Attributes
91104
*/
@@ -95,7 +108,7 @@ public function setAttributes($attributes)
95108
}
96109

97110
/**
98-
* Returns the user locale
111+
* Returns the locale
99112
*
100113
* @return string
101114
*/
@@ -105,16 +118,14 @@ public function getLocale()
105118
}
106119

107120
/**
108-
* Sets the user locale.
121+
* Sets the locale.
109122
*
110123
* @param string $locale
111124
*/
112125
public function setLocale($locale)
113126
{
114127
if ($this->locale != $locale) {
115128
$this->setAttribute('_locale', $locale);
116-
117-
$this->dispatcher->notify(new Event($this, 'user.change_locale', array('locale' => $locale)));
118129
}
119130
}
120131

@@ -146,8 +157,10 @@ public function hasFlash($name)
146157

147158
public function __destruct()
148159
{
149-
$this->attributes['_flash'] = array_diff_key($this->attributes['_flash'], $this->oldFlashes);
160+
if (true === $this->started) {
161+
$this->attributes['_flash'] = array_diff_key($this->attributes['_flash'], $this->oldFlashes);
150162

151-
$this->session->write('_user', $this->attributes);
163+
$this->storage->write('_symfony2', $this->attributes);
164+
}
152165
}
153166
}

‎src/Symfony/Framework/FoundationBundle/Session/NativeSession.php renamed to ‎src/Symfony/Components/HttpFoundation/SessionStorage/NativeSessionStorage.php

Copy file name to clipboardExpand all lines: src/Symfony/Components/HttpFoundation/SessionStorage/NativeSessionStorage.php
+26-22Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Framework\FoundationBundle\Session;
3+
namespace Symfony\Components\HttpFoundation\SessionStorage;
44

55
/*
66
* This file is part of the Symfony framework.
@@ -12,13 +12,13 @@
1212
*/
1313

1414
/**
15-
* NativeSession.
15+
* NativeSessionStorage.
1616
*
1717
* @package Symfony
18-
* @subpackage Framework_FoundationBundle
18+
* @subpackage Components_HttpFoundation
1919
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2020
*/
21-
class NativeSession implements SessionInterface
21+
class NativeSessionStorage implements SessionStorageInterface
2222
{
2323
static protected $sessionIdRegenerated = false;
2424
static protected $sessionStarted = false;
@@ -30,7 +30,6 @@ class NativeSession implements SessionInterface
3030
*
3131
* * session_name: The cookie name (symfony by default)
3232
* * session_id: The session id (null by default)
33-
* * auto_start: Whether to start the session (true by default)
3433
* * session_cookie_lifetime: Cookie lifetime
3534
* * session_cookie_path: Cookie path
3635
* * session_cookie_domain: Cookie domain
@@ -48,39 +47,44 @@ public function __construct(array $options = array())
4847

4948
$this->options = array_merge(array(
5049
'session_name' => 'SYMFONY_SESSION',
51-
'auto_start' => true,
5250
'session_cookie_lifetime' => $cookieDefaults['lifetime'],
5351
'session_cookie_path' => $cookieDefaults['path'],
5452
'session_cookie_domain' => $cookieDefaults['domain'],
5553
'session_cookie_secure' => $cookieDefaults['secure'],
5654
'session_cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
5755
'session_cache_limiter' => 'none',
5856
), $options);
57+
}
5958

60-
// set session name
61-
$sessionName = $this->options['session_name'];
62-
63-
session_name($sessionName);
64-
65-
if (!(boolean) ini_get('session.use_cookies') && $sessionId = $this->options['session_id']) {
66-
session_id($sessionId);
59+
/**
60+
* Starts the session.
61+
*/
62+
public function start()
63+
{
64+
if (self::$sessionStarted) {
65+
return;
6766
}
6867

69-
$lifetime = $this->options['session_cookie_lifetime'];
70-
$path = $this->options['session_cookie_path'];
71-
$domain = $this->options['session_cookie_domain'];
72-
$secure = $this->options['session_cookie_secure'];
73-
$httpOnly = $this->options['session_cookie_httponly'];
74-
session_set_cookie_params($lifetime, $path, $domain, $secure, $httpOnly);
68+
session_set_cookie_params(
69+
$this->options['session_cookie_lifetime'],
70+
$this->options['session_cookie_path'],
71+
$this->options['session_cookie_domain'],
72+
$this->options['session_cookie_secure'],
73+
$this->options['session_cookie_httponly']
74+
);
75+
session_name($this->options['session_name']);
7576

7677
if (null !== $this->options['session_cache_limiter']) {
7778
session_cache_limiter($this->options['session_cache_limiter']);
7879
}
7980

80-
if ($this->options['auto_start'] && !self::$sessionStarted) {
81-
session_start();
82-
self::$sessionStarted = true;
81+
if (!ini_get('session.use_cookies') && $this->options['session_id'] && $this->options['session_id'] != session_id()) {
82+
session_id($this->options['session_id']);
8383
}
84+
85+
session_start();
86+
87+
self::$sessionStarted = true;
8488
}
8589

8690
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.