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

Commit 5bd7ceb

Browse files
committed
Merge branch 'feature/forwards-compat' into develop
Close #29
2 parents c4b6f01 + 452286a commit 5bd7ceb

17 files changed

+506
-289
lines changed

.travis.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ matrix:
1717
- php: 5.5
1818
env:
1919
- EXECUTE_CS_CHECK=true
20+
- php: 5.5
21+
env:
22+
- EVENT_MANAGER_VERSION="^2.6.2"
23+
- SERVICE_MANAGER_VERSION="^2.7.5"
2024
- php: 5.6
2125
env:
2226
- EXECUTE_TEST_COVERALLS=true
27+
- php: 5.6
28+
env:
29+
- EVENT_MANAGER_VERSION="^2.6.2"
30+
- SERVICE_MANAGER_VERSION="^2.7.5"
31+
- php: 7
2332
- php: 7
33+
env:
34+
- EVENT_MANAGER_VERSION="^2.6.2"
35+
- SERVICE_MANAGER_VERSION="^2.7.5"
36+
- php: hhvm
2437
- php: hhvm
38+
env:
39+
- EVENT_MANAGER_VERSION="^2.6.2"
40+
- SERVICE_MANAGER_VERSION="^2.7.5"
2541
allow_failures:
26-
- php: 7
2742
- php: hhvm
2843

2944
notifications:
@@ -34,6 +49,10 @@ before_install:
3449
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
3550
- composer self-update
3651
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
52+
- if [[ $EVENT_MANAGER_VERSION != '' ]]; then composer require --no-update "zendframework/zend-eventmanager:$EVENT_MANAGER_VERSION" ; fi
53+
- if [[ $EVENT_MANAGER_VERSION == '' ]]; then composer require --no-update "zendframework/zend-eventmanager:^3.0" ; fi
54+
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
55+
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
3756

3857
install:
3958
- travis_retry composer install --no-interaction --ignore-platform-reqs

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 2.6.0 - 2016-02-23
6+
7+
### Added
8+
9+
- [#29](https://github.com/zendframework/zend-session/pull/29) adds two new
10+
classes: `Zend\Session\Validator\ValidatorChainEM2` and `ValidatorChainEM3`.
11+
Due to differences in the `EventManagerInterface::attach()` method between
12+
zend-eventmanager v2 and v3, and the fact that `ValidatorChain` overrides that
13+
method, we now need an implementation targeting each major version. To provide
14+
a consistent use case, we use a polyfill that aliases the appropriate version
15+
to the `Zend\Session\ValidatorChain` class.
16+
17+
### Deprecated
18+
19+
- Nothing.
20+
21+
### Removed
22+
23+
- Nothing.
24+
25+
### Fixed
26+
27+
- [#29](https://github.com/zendframework/zend-session/pull/29) updates the code
28+
to be forwards compatible with the v3 releases of zend-eventmanager and
29+
zend-servicemanager.
30+
531
## 2.5.3 - TBD
632

733
### Added

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
}
1414
},
1515
"require": {
16-
"php": ">=5.5",
17-
"zendframework/zend-eventmanager": "dev-develop as 2.7",
18-
"zendframework/zend-stdlib": "~2.5"
16+
"php": "^5.5 || ^7.0",
17+
"zendframework/zend-eventmanager": "^2.6.2 || ^3.0",
18+
"zendframework/zend-stdlib": "^2.7 || ^3.0"
1919
},
2020
"require-dev": {
21-
"zendframework/zend-cache": "~2.5",
22-
"zendframework/zend-db": "~2.5",
23-
"zendframework/zend-http": "~2.5",
24-
"zendframework/zend-servicemanager": "dev-develop as 2.5",
25-
"zendframework/zend-validator": "~2.5",
21+
"zendframework/zend-cache": "^2.6.1",
22+
"zendframework/zend-db": "^2.7",
23+
"zendframework/zend-http": "^2.5.4",
24+
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
25+
"zendframework/zend-validator": "^2.6",
2626
"container-interop/container-interop": "^1.1",
2727
"fabpot/php-cs-fixer": "1.7.*",
2828
"phpunit/PHPUnit": "~4.0"

src/Service/ContainerAbstractServiceFactory.php

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
namespace Zend\Session\Service;
1111

1212
use Interop\Container\ContainerInterface;
13-
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
13+
use Zend\ServiceManager\AbstractFactoryInterface;
14+
use Zend\ServiceManager\ServiceLocatorInterface;
1415
use Zend\Session\Container;
16+
use Zend\Session\ManagerInterface;
1517

1618
/**
1719
* Session container abstract service factory.
1820
*
19-
* Allows creating Container instances, using the Zend\Service\ManagerInterface
21+
* Allows creating Container instances, using the ManagerInterface
2022
* if present. Containers are named in a "session_containers" array in the
2123
* Config service:
2224
*
@@ -51,16 +53,18 @@ class ContainerAbstractServiceFactory implements AbstractFactoryInterface
5153
protected $configKey = 'session_containers';
5254

5355
/**
54-
* @var \Zend\Session\ManagerInterface
56+
* @var ManagerInterface
5557
*/
5658
protected $sessionManager;
5759

5860
/**
59-
* @param ContainerInterface $container
60-
* @param string $requestedName
61+
* Can we create an instance of the given service? (v3 usage).
62+
*
63+
* @param ContainerInterface $container
64+
* @param string $requestedName
6165
* @return bool
6266
*/
63-
public function canCreateServiceWithName(ContainerInterface $container, $requestedName)
67+
public function canCreate(ContainerInterface $container, $requestedName)
6468
{
6569
$config = $this->getConfig($container);
6670
if (empty($config)) {
@@ -72,17 +76,43 @@ public function canCreateServiceWithName(ContainerInterface $container, $request
7276
}
7377

7478
/**
75-
* @param ContainerInterface $container
76-
* @param string $requestedName
77-
* @return Container
79+
* Can we create an instance of the given service? (v2 usage)
80+
*
81+
* @param ServiceLocatorInterface $container
82+
* @param string $name
83+
* @param string $requestedName
84+
* @return bool
7885
*/
86+
public function canCreateServiceWithName(ServiceLocatorInterface $container, $name, $requestedName)
87+
{
88+
return $this->canCreate($container, $requestedName);
89+
}
7990

91+
/**
92+
* Create and return a named container (v3 usage).
93+
*
94+
* @param ContainerInterface $container
95+
* @param string $requestedName
96+
* @return Container
97+
*/
8098
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
8199
{
82100
$manager = $this->getSessionManager($container);
83101
return new Container($requestedName, $manager);
84102
}
85103

104+
/**
105+
* Create and return a named container (v2 usage).
106+
*
107+
* @param ContainerInterface $container
108+
* @param string $requestedName
109+
* @return Container
110+
*/
111+
public function createServiceWithName(ServiceLocatorInterface $container, $name, $requestedName)
112+
{
113+
return $this($container, $requestedName);
114+
}
115+
86116
/**
87117
* Retrieve config from service locator, and cache for later
88118
*
@@ -101,7 +131,7 @@ protected function getConfig(ContainerInterface $container)
101131
}
102132

103133
$config = $container->get('config');
104-
if (!isset($config[$this->configKey]) || !is_array($config[$this->configKey])) {
134+
if (! isset($config[$this->configKey]) || ! is_array($config[$this->configKey])) {
105135
$this->config = [];
106136
return $this->config;
107137
}
@@ -118,16 +148,16 @@ protected function getConfig(ContainerInterface $container)
118148
* Retrieve the session manager instance, if any
119149
*
120150
* @param ContainerInterface $container
121-
* @return null|\Zend\Session\ManagerInterface
151+
* @return null|ManagerInterface
122152
*/
123153
protected function getSessionManager(ContainerInterface $container)
124154
{
125155
if ($this->sessionManager !== null) {
126156
return $this->sessionManager;
127157
}
128158

129-
if ($container->has('Zend\Session\ManagerInterface')) {
130-
$this->sessionManager = $container->get('Zend\Session\ManagerInterface');
159+
if ($container->has(ManagerInterface::class)) {
160+
$this->sessionManager = $container->get(ManagerInterface::class);
131161
}
132162

133163
return $this->sessionManager;

src/Service/SessionConfigFactory.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,44 @@
1111

1212
use Interop\Container\ContainerInterface;
1313
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
14-
use Zend\ServiceManager\Factory\FactoryInterface;
14+
use Zend\ServiceManager\FactoryInterface;
15+
use Zend\ServiceManager\ServiceLocatorInterface;
1516
use Zend\Session\Config\ConfigInterface;
17+
use Zend\Session\Config\SessionConfig;
1618

1719
class SessionConfigFactory implements FactoryInterface
1820
{
1921
/**
20-
* Create session configuration object
22+
* Create session configuration object (v3 usage).
2123
*
2224
* Uses "session_config" section of configuration to seed a ConfigInterface
2325
* instance. By default, Zend\Session\Config\SessionConfig will be used, but
2426
* you may also specify a specific implementation variant using the
2527
* "config_class" subkey.
2628
*
27-
* @param ContainerInterface $container
29+
* @param ContainerInterface $container
30+
* @param string $requestedName
31+
* @param null|array $options
2832
* @return ConfigInterface
2933
* @throws ServiceNotCreatedException if session_config is missing, or an
30-
* invalid config_class is used
34+
* invalid config_class is used
3135
*/
3236
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
3337
{
3438
$config = $container->get('config');
35-
if (!isset($config['session_config']) || !is_array($config['session_config'])) {
39+
if (! isset($config['session_config']) || ! is_array($config['session_config'])) {
3640
throw new ServiceNotCreatedException(
3741
'Configuration is missing a "session_config" key, or the value of that key is not an array'
3842
);
3943
}
40-
$class = 'Zend\Session\Config\SessionConfig';
44+
45+
$class = SessionConfig::class;
4146
$config = $config['session_config'];
4247
if (isset($config['config_class'])) {
43-
if (!class_exists($config['config_class'])) {
48+
if (! class_exists($config['config_class'])) {
4449
throw new ServiceNotCreatedException(sprintf(
45-
'Invalid configuration class "%s" specified in "config_class" session configuration; must be a valid class',
50+
'Invalid configuration class "%s" specified in "config_class" session configuration; '
51+
. 'must be a valid class',
4652
$config['config_class']
4753
));
4854
}
@@ -51,14 +57,31 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
5157
}
5258

5359
$sessionConfig = new $class();
54-
if (!$sessionConfig instanceof ConfigInterface) {
60+
if (! $sessionConfig instanceof ConfigInterface) {
5561
throw new ServiceNotCreatedException(sprintf(
56-
'Invalid configuration class "%s" specified in "config_class" session configuration; must implement Zend\Session\Config\ConfigInterface',
57-
$class
62+
'Invalid configuration class "%s" specified in "config_class" session configuration; must implement %s',
63+
$class,
64+
ConfigInterface::class
5865
));
5966
}
6067
$sessionConfig->setOptions($config);
6168

6269
return $sessionConfig;
6370
}
71+
72+
/**
73+
* Create and return a config instance (v2 usage).
74+
*
75+
* @param ServiceLocatorInterface $services
76+
* @param null|string $canonicalName
77+
* @param string $requestedName
78+
* @return ConfigInterface
79+
*/
80+
public function createService(
81+
ServiceLocatorInterface $services,
82+
$canonicalName = null,
83+
$requestedName = ConfigInterface::class
84+
) {
85+
return $this($services, $requestedName);
86+
}
6487
}

src/Service/SessionManagerFactory.php

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
use Interop\Container\ContainerInterface;
1313
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
14-
use Zend\ServiceManager\Factory\FactoryInterface;
14+
use Zend\ServiceManager\FactoryInterface;
15+
use Zend\ServiceManager\ServiceLocatorInterface;
1516
use Zend\Session\Config\ConfigInterface;
1617
use Zend\Session\Container;
1718
use Zend\Session\SaveHandler\SaveHandlerInterface;
@@ -30,7 +31,7 @@ class SessionManagerFactory implements FactoryInterface
3031
];
3132

3233
/**
33-
* Create session manager object
34+
* Create session manager object (v3 usage).
3435
*
3536
* Will consume any combination (or zero) of the following services, when
3637
* present, to construct the SessionManager instance:
@@ -68,37 +69,37 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
6869
$validators = [];
6970
$managerConfig = $this->defaultManagerConfig;
7071

71-
if ($container->has('Zend\Session\Config\ConfigInterface')) {
72-
$config = $container->get('Zend\Session\Config\ConfigInterface');
72+
if ($container->has(ConfigInterface::class)) {
73+
$config = $container->get(ConfigInterface::class);
7374
if (!$config instanceof ConfigInterface) {
7475
throw new ServiceNotCreatedException(sprintf(
7576
'SessionManager requires that the %s service implement %s; received "%s"',
76-
'Zend\Session\Config\ConfigInterface',
77-
'Zend\Session\Config\ConfigInterface',
77+
ConfigInterface::class,
78+
ConfigInterface::class,
7879
(is_object($config) ? get_class($config) : gettype($config))
7980
));
8081
}
8182
}
8283

83-
if ($container->has('Zend\Session\Storage\StorageInterface')) {
84-
$storage = $container->get('Zend\Session\Storage\StorageInterface');
84+
if ($container->has(StorageInterface::class)) {
85+
$storage = $container->get(StorageInterface::class);
8586
if (!$storage instanceof StorageInterface) {
8687
throw new ServiceNotCreatedException(sprintf(
8788
'SessionManager requires that the %s service implement %s; received "%s"',
88-
'Zend\Session\Storage\StorageInterface',
89-
'Zend\Session\Storage\StorageInterface',
89+
StorageInterface::class,
90+
StorageInterface::class,
9091
(is_object($storage) ? get_class($storage) : gettype($storage))
9192
));
9293
}
9394
}
9495

95-
if ($container->has('Zend\Session\SaveHandler\SaveHandlerInterface')) {
96-
$saveHandler = $container->get('Zend\Session\SaveHandler\SaveHandlerInterface');
96+
if ($container->has(SaveHandlerInterface::class)) {
97+
$saveHandler = $container->get(SaveHandlerInterface::class);
9798
if (!$saveHandler instanceof SaveHandlerInterface) {
9899
throw new ServiceNotCreatedException(sprintf(
99100
'SessionManager requires that the %s service implement %s; received "%s"',
100-
'Zend\Session\SaveHandler\SaveHandlerInterface',
101-
'Zend\Session\SaveHandler\SaveHandlerInterface',
101+
SaveHandlerInterface::class,
102+
SaveHandlerInterface::class,
102103
(is_object($saveHandler) ? get_class($saveHandler) : gettype($saveHandler))
103104
));
104105
}
@@ -130,4 +131,20 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
130131

131132
return $manager;
132133
}
134+
135+
/**
136+
* Create a SessionManager instance (v2 usage)
137+
*
138+
* @param ServiceLocatorInterface $services
139+
* @param null|string $canonicalName
140+
* @param string $requestedName
141+
* @return SessionManager
142+
*/
143+
public function createService(
144+
ServiceLocatorInterface $services,
145+
$canonicalName = null,
146+
$requestedName = SessionManager::class
147+
) {
148+
return $this($services, $requestedName);
149+
}
133150
}

0 commit comments

Comments
 (0)