Browse files

Adding setSavePath and getSavePath to SessionStorage to control globa…

…l setting of session_save_path().
  • Loading branch information...
1 parent 80248d2 commit 2381bd3449454dd785140d7fb9bc72ec1f4643f7 @zburnham committed Dec 10, 2012
Showing with 52 additions and 0 deletions.
  1. +35 −0 library/Zend/Session/Storage/SessionStorage.php
  2. +17 −0 tests/ZendTest/Session/SessionStorageTest.php
View
35 library/Zend/Session/Storage/SessionStorage.php
@@ -25,6 +25,13 @@
class SessionStorage extends ArrayStorage
{
/**
+ * Session save path.
+ *
+ * @var string
+ */
+ protected $savePath;
+
+ /**
* Constructor
*
* Sets the $_SESSION superglobal to an ArrayObject, maintaining previous
@@ -103,4 +110,32 @@ public function isImmutable()
{
return (isset($this['_IMMUTABLE']) && $this['_IMMUTABLE']);
}
+
+ /**
+ * Returns the currently set session_save_path() value. Sets the class
+ * property if the class property is stale.
+ *
+ * @return string
+ */
+ public function getSavePath()
+ {
+ $savePath = session_save_path();
+ if ($savePath != $this->savePath) {
+ $this->setSavePath($savePath);
+ }
+ return $this->savePath;
+ }
+
+ /**
+ * Sets the session_save_path() value and the class property.
+ *
+ * @param string $savePath
+ * @return \Zend\Session\Storage\SessionStorage
+ */
+ public function setSavePath($savePath)
+ {
+ session_save_path($savePath);
+ $this->savePath = $savePath;
+ return $this;
+ }
}
View
17 tests/ZendTest/Session/SessionStorageTest.php
@@ -95,4 +95,21 @@ public function testMarkingOneSessionObjectImmutableShouldMarkOtherInstancesImmu
$this->storage->markImmutable();
$this->assertTrue($storage->isImmutable(), var_export($_SESSION, 1));
}
+
+ public function testSetSavePathSetsSessionSavePath()
+ {
+ $savePath = '/this/is/a/path';
+ $this->storage->setSavePath($savePath);
+ $this->assertEquals($savePath, session_save_path());
+ }
+
+ public function testGetSavePathGivesAccuratePath()
+ {
+ $savePath = session_save_path();
+ $testSavePath = $this->storage->getSavePath();
+ $this->assertEquals($savePath, $testSavePath);
+ $savePath = '/this/is/a/path';
+ session_save_path($savePath);
+ $this->assertEquals($savePath, $this->storage->getSavePath());
+ }
}

0 comments on commit 2381bd3

Please sign in to comment.