Skip to content

Commit

Permalink
Merge branch 'customise-storage-key'
Browse files Browse the repository at this point in the history
Closes #35, closes #10
  • Loading branch information
akrabat committed Oct 22, 2017
2 parents 4434777 + a34986f commit 9aaff5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ class Messages
* @throws RuntimeException if the session cannot be found
* @throws InvalidArgumentException if the store is not array-like
*/
public function __construct(&$storage = null)
public function __construct(&$storage = null, $storageKey = null)
{
if (is_string($storageKey) && $storageKey) {
$this->storageKey = $storageKey;
}

// Set storage
if (is_array($storage) || $storage instanceof ArrayAccess) {
$this->storage = &$storage;
Expand Down
10 changes: 10 additions & 0 deletions tests/MessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,14 @@ public function testClearMessage()
$this->assertFalse($flash->hasMessage('Now'));
$this->assertTrue($flash->hasMessage('Foo'));
}

public function testSettingCustomStorageKey()
{
$storage = ['some-key' => [ 'Test' => ['Test']]];
$flash = new Messages($storage);
$this->assertFalse($flash->hasMessage('Test'));

$flash = new Messages($storage, 'some-key');
$this->assertTrue($flash->hasMessage('Test'));
}
}

0 comments on commit 9aaff5f

Please sign in to comment.