Skip to content

Commit

Permalink
Apply Prettier codestyle to everything
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjhv committed May 27, 2020
1 parent 9783c04 commit 11fa98c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
28 changes: 15 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ composer require bryanjhv/slim-session:~4.0

```php
$app = \Slim\Factory\AppFactory::create();
$app->add(new \Slim\Middleware\Session([
'name' => 'dummy_session',
'autorefresh' => true,
'lifetime' => '1 hour'
]));
$app->add(
new \Slim\Middleware\Session([
'name' => 'dummy_session',
'autorefresh' => true,
'lifetime' => '1 hour',
])
);
```

### Supported options
Expand All @@ -52,22 +54,22 @@ $app->add(new \Slim\Middleware\Session([
serious performance leaks (see #30):
```php
[
'session.gc_divisor' => 1,
'session.gc_probability' => 1,
'session.gc_maxlifetime' => 30 * 24 * 60 * 60,
]
'session.gc_divisor' => 1,
'session.gc_probability' => 1,
'session.gc_maxlifetime' => 30 * 24 * 60 * 60,
];
```

## Session helper

A `Helper` class is available, which you can register globally or instantiate:

```php
$container = new \DI\Container;
$container = new \DI\Container();

// Register globally to app
$container->set('session', function () {
return new \SlimSession\Helper;
return new \SlimSession\Helper();
});
\Slim\Factory\AppFactory::setContainer($container);
```
Expand All @@ -77,7 +79,7 @@ That will provide `$app->get('session')`, so you can do:
```php
$app->get('/', function ($req, $res) {
// or $this->get('session') if registered
$session = new \SlimSession\Helper;
$session = new \SlimSession\Helper();

// Check if variable exists
$exists = $session->exists('my_key');
Expand All @@ -97,7 +99,7 @@ $app->get('/', function ($req, $res) {
// Merge value recursively
$app->get('session')->merge('my_key', ['first' => 'value']);
$session->merge('my_key', ['second' => ['a' => 'A']]);
$letter_a = $session['my_key']['second']['a']; // "A"
$letter_a = $session['my_key']['second']['a']; // "A"

// Delete variable
$session->delete('my_key');
Expand Down
30 changes: 18 additions & 12 deletions tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function setUp()

public function testExists()
{
$helper = new Helper;
$helper = new Helper();

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

Expand All @@ -30,7 +30,7 @@ public function testExists()

public function testSet()
{
$helper = new Helper;
$helper = new Helper();

$helper->set('a', 'A');
$this->assertSame(['a' => 'A'], $_SESSION);
Expand All @@ -44,22 +44,28 @@ public function testSet()

public function testMerge()
{
$helper = new Helper;
$helper = new Helper();
$helper->set('a', []);

$helper->merge('a', ['a' => 'A']);
$this->assertSame(['a' => ['a' => 'A']], $_SESSION);

$helper->merge('a', ['b' => ['a' => 'A']]);
$this->assertSame(['a' => ['a' => 'A', 'b' => ['a' => 'A']]], $_SESSION);
$this->assertSame(
['a' => ['a' => 'A', 'b' => ['a' => 'A']]],
$_SESSION
);

$helper->merge('a', ['b' => ['b' => 'B']]);
$this->assertSame(['a' => ['a' => 'A', 'b' => ['a' => 'A', 'b' => 'B']]], $_SESSION);
$this->assertSame(
['a' => ['a' => 'A', 'b' => ['a' => 'A', 'b' => 'B']]],
$_SESSION
);
}

public function testGet()
{
$helper = new Helper;
$helper = new Helper();

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

Expand All @@ -76,7 +82,7 @@ public function testGet()

public function testDelete()
{
$helper = new Helper;
$helper = new Helper();

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

Expand All @@ -96,7 +102,7 @@ public function testDelete()

public function testClear()
{
$helper = new Helper;
$helper = new Helper();

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

Expand All @@ -109,7 +115,7 @@ public function testClear()
*/
public function testId()
{
$helper = new Helper;
$helper = new Helper();

$this->assertSame(session_id(), $helper::id());
$this->assertNotSame(session_id(), $sessionId = $helper::id(true));
Expand All @@ -121,7 +127,7 @@ public function testId()
*/
public function testDestroy()
{
$helper = new Helper;
$helper = new Helper();

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

Expand All @@ -140,7 +146,7 @@ public function testDestroy()

public function testCount()
{
$helper = new Helper;
$helper = new Helper();

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

Expand All @@ -149,7 +155,7 @@ public function testCount()

public function testIterator()
{
$helper = new Helper;
$helper = new Helper();

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

Expand Down

0 comments on commit 11fa98c

Please sign in to comment.