diff --git a/src/Symfony/Component/HttpFoundation/Session/Session.php b/src/Symfony/Component/HttpFoundation/Session/Session.php index c68bd30fce..cbadcd38a2 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session/Session.php @@ -11,7 +11,7 @@ namespace Symfony\Component\HttpFoundation\Session; -use Symfony\Component\HttpFoundation\Session\Storage\MetaBag; +use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface; @@ -212,9 +212,9 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable /** * {@iheritdoc} */ - public function getMetadata() + public function getMetadataBag() { - return $this->storage->getMetaBag(); + return $this->storage->getMetadataBag(); } /** diff --git a/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php b/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php index bfd7f6abb8..15b4c2924c 100644 --- a/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php @@ -193,7 +193,7 @@ interface SessionInterface /** * Gets session meta. * - * @return MetaBag + * @return MetadataBag */ - public function getMeta(); + public function getMetadataBag(); } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MetaBag.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php similarity index 72% rename from src/Symfony/Component/HttpFoundation/Session/Storage/MetaBag.php rename to src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php index 0bb160f843..892d004b5d 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MetaBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php @@ -16,16 +16,20 @@ use Symfony\Component\HttpFoundation\Session\SessionBagInterface; /** * Metadata container. * - * Adds meta data to the session. + * Adds metadata to the session. * * @author Drak */ -class MetaBag implements SessionBagInterface +class MetadataBag implements SessionBagInterface { + const CREATED = 'c'; + const UPDATED = 'u'; + const LIFETIME = 'l'; + /** * @var string */ - private $name = '__meta'; + private $name = '__metadata'; /** * @var string @@ -52,19 +56,19 @@ class MetaBag implements SessionBagInterface public function __construct($storageKey = '_sf2_meta') { $this->storageKey = $storageKey; - $this->meta = array('created' => 0, 'lastused' => 0, 'lifetime' => 0); + $this->meta = array(self::CREATED => 0, self::UPDATED => 0, self::LIFETIME => 0); } /** * {@inheritdoc} */ - public function initialize(array &$meta) + public function initialize(array &$array) { - $this->meta = &$meta; + $this->meta = &$array; - if (isset($meta['created'])) { - $this->lastUsed = $this->meta['lastused']; - $this->meta['lastused'] = time(); + if (isset($array[self::CREATED])) { + $this->lastUsed = $this->meta[self::UPDATED]; + $this->meta[self::UPDATED] = time(); } else { $this->stampCreated(); } @@ -77,11 +81,11 @@ class MetaBag implements SessionBagInterface */ public function getLifetime() { - return $this->meta['lifetime']; + return $this->meta[self::LIFETIME]; } /** - * Stamps a new session's meta. + * Stamps a new session's metadata. * * @param integer $lifetime Sets the cookie lifetime for the session cookie. A null value * will leave the system settings unchanged, 0 sets the cookie @@ -102,17 +106,17 @@ class MetaBag implements SessionBagInterface } /** - * Gets the created timestamp meta data. + * Gets the created timestamp metadata. * * @return integer Unix timestamp */ public function getCreated() { - return $this->meta['created']; + return $this->meta[self::CREATED]; } /** - * Gets the last used meta data. + * Gets the last used metadata. * * @return integer Unix timestamp */ @@ -150,7 +154,7 @@ class MetaBag implements SessionBagInterface private function stampCreated($lifetime = null) { $timeStamp = time(); - $this->meta['created'] = $this->meta['lastused'] = $this->lastUsed = $timeStamp; - $this->meta['lifetime'] = (null === $lifetime) ? ini_get('session.cookie_lifetime') : $lifetime; + $this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp; + $this->meta[self::LIFETIME] = (null === $lifetime) ? ini_get('session.cookie_lifetime') : $lifetime; } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index f77116a014..5500a03419 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -12,7 +12,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage; use Symfony\Component\HttpFoundation\Session\SessionBagInterface; -use Symfony\Component\HttpFoundation\Session\Storage\MetaBag; +use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; /** * MockArraySessionStorage mocks the session for unit tests. @@ -54,20 +54,20 @@ class MockArraySessionStorage implements SessionStorageInterface protected $data = array(); /** - * @var MetaBag + * @var MetadataBag */ - protected $metaBag; + protected $metadataBag; /** * Constructor. * * @param string $name Session name - * @param MetaBag $metaBag MetaBag instance. + * @param MetadataBag $metaBag MetadataBag instance. */ - public function __construct($name = 'MOCKSESSID', MetaBag $metaBag = null) + public function __construct($name = 'MOCKSESSID', MetadataBag $metaBag = null) { $this->name = $name; - $this->setMetaBag($metaBag); + $this->setMetadataBag($metaBag); } /** @@ -107,7 +107,7 @@ class MockArraySessionStorage implements SessionStorageInterface $this->start(); } - $this->metaBag->stampNew($lifetime); + $this->metadataBag->stampNew($lifetime); $this->id = $this->generateId(); return true; @@ -200,27 +200,27 @@ class MockArraySessionStorage implements SessionStorageInterface } /** - * Sets the metabag. + * Sets the MetadataBag. * - * @param MetaBag $metaBag + * @param MetadataBag $bag */ - public function setMetaBag(MetaBag $metaBag = null) + public function setMetadataBag(MetadataBag $bag = null) { - if (null === $metaBag) { - $metaBag = new MetaBag(); + if (null === $bag) { + $bag = new MetadataBag(); } - $this->metaBag = $metaBag; + $this->metadataBag = $bag; } /** - * Gets the MetaBag. + * Gets the MetadataBag. * - * @return MetaBag + * @return MetadataBag */ - public function getMetaBag() + public function getMetadataBag() { - return $this->metaBag; + return $this->metadataBag; } /** @@ -238,7 +238,7 @@ class MockArraySessionStorage implements SessionStorageInterface protected function loadSession() { - $bags = array_merge($this->bags, array($this->metaBag)); + $bags = array_merge($this->bags, array($this->metadataBag)); foreach ($bags as $bag) { $key = $bag->getStorageKey(); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 72b3f5c79a..215ed26ab0 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -12,7 +12,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage; use Symfony\Component\HttpFoundation\Session\SessionBagInterface; -use Symfony\Component\HttpFoundation\Session\Storage\MetaBag; +use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; @@ -47,9 +47,9 @@ class NativeSessionStorage implements SessionStorageInterface protected $saveHandler; /** - * @var MetaBag + * @var MetadataBag */ - protected $metaBag; + protected $metadataBag; /** * Constructor. @@ -91,9 +91,9 @@ class NativeSessionStorage implements SessionStorageInterface * * @param array $options Session configuration options. * @param object $handler SessionHandlerInterface. - * @param MetaBag $handler MetaBag. + * @param MetadataBag $handler MetadataBag. */ - public function __construct(array $options = array(), $handler = null, MetaBag $metaBag = null) + public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null) { // sensible defaults ini_set('session.auto_start', 0); // by default we prefer to explicitly start the session using the class. @@ -106,7 +106,7 @@ class NativeSessionStorage implements SessionStorageInterface register_shutdown_function('session_write_close'); } - $this->setMetaBag($metaBag); + $this->setMetadataBag($metaBag); $this->setOptions($options); $this->setSaveHandler($handler); } @@ -202,7 +202,7 @@ class NativeSessionStorage implements SessionStorageInterface } if ($destroy) { - $this->metaBag->stampNew(); + $this->metadataBag->stampNew(); } return session_regenerate_id($destroy); @@ -266,27 +266,27 @@ class NativeSessionStorage implements SessionStorageInterface } /** - * Sets the metabag. + * Sets the MetadataBag. * - * @param MetaBag $metaBag + * @param MetadataBag $metaBag */ - public function setMetaBag(MetaBag $metaBag = null) + public function setMetadataBag(MetadataBag $metaBag = null) { if (null === $metaBag) { - $metaBag = new MetaBag(); + $metaBag = new MetadataBag(); } - $this->metaBag = $metaBag; + $this->metadataBag = $metaBag; } /** - * Gets the MetaBag. + * Gets the MetadataBag. * - * @return MetaBag + * @return MetadataBag */ - public function getMetaBag() + public function getMetadataBag() { - return $this->metaBag; + return $this->metadataBag; } /** @@ -378,7 +378,7 @@ class NativeSessionStorage implements SessionStorageInterface $session = &$_SESSION; } - $bags = array_merge($this->bags, array($this->metaBag)); + $bags = array_merge($this->bags, array($this->metadataBag)); foreach ($bags as $bag) { $key = $bag->getStorageKey(); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php index 1c1014b89f..20c533c2eb 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php @@ -12,7 +12,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage; use Symfony\Component\HttpFoundation\Session\SessionBagInterface; -use Symfony\Component\HttpFoundation\Session\Storage\MetaBag; +use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; /** * StorageInterface. @@ -130,7 +130,7 @@ interface SessionStorageInterface function registerBag(SessionBagInterface $bag); /** - * @return MetaBag + * @return MetadataBag */ - function getMetaBag(); + function getMetadataBag(); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php index cb903369c6..bd45b2fbe6 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php @@ -12,7 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session; use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\HttpFoundation\Session\MetaBag; +use Symfony\Component\HttpFoundation\Session\MetadataBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; @@ -257,6 +257,6 @@ class SessionTest extends \PHPUnit_Framework_TestCase public function testGetMeta() { - $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\MetaBag', $this->session->getMeta()); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\MetadataBag', $this->session->getMetadataBag()); } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetaBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php similarity index 79% rename from src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetaBagTest.php rename to src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php index a3b578c4cb..39f268b4b5 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetaBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php @@ -11,15 +11,15 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; -use Symfony\Component\HttpFoundation\Session\Storage\MetaBag; +use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; /** - * Test class for MetaBag. + * Test class for MetadataBag. */ -class MetaBagTest extends \PHPUnit_Framework_TestCase +class MetadataBagTest extends \PHPUnit_Framework_TestCase { /** - * @var MetaBag + * @var MetadataBag */ protected $bag; @@ -30,8 +30,8 @@ class MetaBagTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->bag = new MetaBag(); - $this->array = array('created' => 1234567, 'lastused' => 12345678); + $this->bag = new MetadataBag(); + $this->array = array(MetadataBag::CREATED => 1234567, MetadataBag::UPDATED => 12345678, MetadataBag::LIFETIME => 0); $this->bag->initialize($this->array); } @@ -43,17 +43,17 @@ class MetaBagTest extends \PHPUnit_Framework_TestCase public function testInitialize() { - $p = new \ReflectionProperty('Symfony\Component\HttpFoundation\Session\Storage\MetaBag', 'meta'); + $p = new \ReflectionProperty('Symfony\Component\HttpFoundation\Session\Storage\MetadataBag', 'meta'); $p->setAccessible(true); - $bag1 = new MetaBag(); + $bag1 = new MetadataBag(); $array = array(); $bag1->initialize($array); $this->assertGreaterThanOrEqual(time(), $bag1->getCreated()); $this->assertEquals($bag1->getCreated(), $bag1->getLastUsed()); sleep(1); - $bag2 = new MetaBag(); + $bag2 = new MetadataBag(); $array2 = $p->getValue($bag1); $bag2->initialize($array2); $this->assertEquals($bag1->getCreated(), $bag2->getCreated()); @@ -61,7 +61,7 @@ class MetaBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals($bag2->getCreated(), $bag2->getLastUsed()); sleep(1); - $bag3 = new MetaBag(); + $bag3 = new MetadataBag(); $array3 = $p->getValue($bag2); $bag3->initialize($array3); $this->assertEquals($bag1->getCreated(), $bag3->getCreated()); @@ -71,7 +71,7 @@ class MetaBagTest extends \PHPUnit_Framework_TestCase public function testGetSetName() { - $this->assertEquals('__meta', $this->bag->getName()); + $this->assertEquals('__metadata', $this->bag->getName()); $this->bag->setName('foo'); $this->assertEquals('foo', $this->bag->getName());