Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit bf7956b

Browse files
committed
Merge branch 'hotfix/122' into develop
Forward port #122
2 parents 17c39cf + d0ee910 commit bf7956b

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ All notable changes to this project will be documented in this file, in reverse
4444

4545
### Fixed
4646

47-
- Nothing.
47+
- [#122](https://github.com/zendframework/zend-session/pull/122) fixes
48+
type check for configuration of session storage. Allows input to be
49+
an instance of ArrayAccess or an array.
4850

4951
## 2.8.6 - 2019-08-11
5052

src/Storage/Factory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,16 @@ protected static function createSessionArrayStorage($type, array $options)
131131
{
132132
$input = null;
133133
if (isset($options['input'])) {
134-
if (null !== $options['input']
135-
&& ! is_array($options['input'])
134+
$input = $options['input'];
135+
if (! is_array($input)
136136
&& ! $input instanceof ArrayAccess
137137
) {
138138
throw new Exception\InvalidArgumentException(sprintf(
139139
'%s expects the "input" option to be null, an array, or to implement ArrayAccess; received "%s"',
140140
$type,
141-
(is_object($options['input']) ? get_class($options['input']) : gettype($options['input']))
141+
is_object($input) ? get_class($input) : gettype($input)
142142
));
143143
}
144-
$input = $options['input'];
145144
}
146145

147146
return new $type($input);

test/Service/StorageFactoryTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\Session\Service;
1111

12+
use ArrayObject;
1213
use PHPUnit\Framework\TestCase;
1314
use Zend\ServiceManager\Config;
1415
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
@@ -68,6 +69,16 @@ public function sessionStorageConfig()
6869
],
6970
],
7071
], SessionArrayStorage::class],
72+
'session-array-storage-arrayobject' => [[
73+
'session_storage' => [
74+
'type' => 'SessionArrayStorage',
75+
'options' => [
76+
'input' => new ArrayObject([
77+
'foo' => 'bar',
78+
]),
79+
],
80+
],
81+
], SessionArrayStorage::class],
7182
'session-array-storage-fqcn' => [[
7283
'session_storage' => [
7384
'type' => SessionArrayStorage::class,
@@ -93,6 +104,21 @@ public function testUsesConfigurationToCreateStorage($config, $class)
93104
$this->assertEquals($config['session_storage']['options']['input'], $test);
94105
}
95106

107+
public function testConfigurationWithoutInputIsValid()
108+
{
109+
$this->services->setService('config', [
110+
'session_storage' => [
111+
'type' => SessionArrayStorage::class,
112+
'options' => [],
113+
],
114+
]);
115+
116+
$storage = $this->services->get(StorageInterface::class);
117+
118+
$this->assertInstanceOf(SessionArrayStorage::class, $storage);
119+
$this->assertSame([], $storage->toArray());
120+
}
121+
96122
public function invalidSessionStorageConfig()
97123
{
98124
return [

0 commit comments

Comments
 (0)