Skip to content

Commit

Permalink
Cosmetics for #26
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjhv committed Nov 25, 2017
1 parent da569cd commit 493496d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ $app->add(new \Slim\Middleware\Session([
PHP's `PHPSESSID`).
* **`autorefresh`**: `true` if you want session to be refresh when user activity
is made (interaction with server).
* `handler`: Class name of the handler which **MUST** be an implementation for ```SessionHandlerInterface```.
* `handler`: Custom session handler class or object. Must implement
`SessionHandlerInterface` as required by PHP.


## Session helper
Expand Down
11 changes: 9 additions & 2 deletions src/Slim/Middleware/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ protected function startSession()
{
$settings = $this->settings;
$name = $settings['name'];
$handler = new $settings['handler'];

session_set_cookie_params(
$settings['lifetime'],
Expand Down Expand Up @@ -109,7 +108,15 @@ protected function startSession()
}

session_name($name);
session_set_save_handler($handler, true);

$handler = $settings['handler'];
if ($handler) {
if (!($handler instanceof SessionHandlerInterface)) {
$handler = new $handler;
}
session_set_save_handler($handler, true);
}

session_cache_limiter(false);
if ($inactive) {
session_start();
Expand Down
5 changes: 2 additions & 3 deletions tests/HelperTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
namespace Tests;

use SlimSession\Helper;

session_start();

class HelperTest extends \PHPUnit_Framework_TestCase
class HelperTest extends PHPUnit_Framework_TestCase
{
protected function setUp()
{
Expand Down Expand Up @@ -153,7 +152,7 @@ public function testIterator()

$_SESSION = ['a' => 'A', 'b' => 'B', 'c' => 'C'];

$this->assertInstanceOf(\Iterator::class, $helper->getIterator());
$this->assertInstanceOf(Iterator::class, $helper->getIterator());
$this->assertSame($_SESSION, iterator_to_array($helper->getIterator()));
}
}

0 comments on commit 493496d

Please sign in to comment.