3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Session\Service
;
12 use Zend\ServiceManager\Exception\ServiceNotCreatedException
;
13 use Zend\ServiceManager\FactoryInterface
;
14 use Zend\ServiceManager\ServiceLocatorInterface
;
15 use Zend\Session\Storage\Exception
as SessionException
;
16 use Zend\Session\Storage\Factory
;
17 use Zend\Session\Storage\StorageInterface
;
19 class StorageFactory
implements FactoryInterface
22 * Create session storage object
24 * Uses "session_storage" section of configuration to seed a StorageInterface
25 * instance. That array should contain the key "type", specifying the storage
26 * type to use, and optionally "options", containing any options to be used in
27 * creating the StorageInterface instance.
29 * @param ServiceLocatorInterface $services
30 * @return StorageInterface
31 * @throws ServiceNotCreatedException if session_storage is missing, or the
32 * factory cannot create the storage instance.
34 public function createService(ServiceLocatorInterface
$services)
36 $config = $services->get('Config');
37 if (!isset($config['session_storage']) ||
!is_array($config['session_storage'])) {
38 throw new ServiceNotCreatedException(
39 'Configuration is missing a "session_storage" key, or the value of that key is not an array'
43 $config = $config['session_storage'];
44 if (!isset($config['type'])) {
45 throw new ServiceNotCreatedException(
46 '"session_storage" configuration is missing a "type" key'
49 $type = $config['type'];
50 $options = isset($config['options']) ?
$config['options'] : array();
53 $storage = Factory
::factory($type, $options);
54 } catch (SessionException
$e) {
55 throw new ServiceNotCreatedException(sprintf(
56 'Factory is unable to create StorageInterface instance: %s',
58 ), $e->getCode(), $e);