Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $manager = parent::createService($serviceLocator);
     $storage = $manager->getStorage();
     if (!$storage->isImmutable() && !$storage->getMetadata('_STRICT')) {
         $manager->regenerateId(false);
         $storage->setMetadata('_STRICT', true);
     }
     return $manager;
 }
 public function createService(ServiceLocatorInterface $sm)
 {
     $config = $sm->get('config');
     if (isset($config['session'])) {
         $session = $config['session'];
         $sessionConfig = null;
         //если есть ключ, проверить базовые настройки
         if (isset($session['config'])) {
             $class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
             $options = isset($session['config']['options']) ? $session['config']['options'] : array();
             $sessionConfig = new $class();
             $sessionConfig->setOptions($options);
         }
         //настройка типа хранилища
         $sessionStorage = null;
         if (isset($session['storage'])) {
             $class = $session['storage'];
             $sessionStorage = new $class();
         }
         //не настроено
         $sessionSaveHandler = null;
         if (isset($session['save_handler'])) {
             // class should be fetched from service manager since
             // it will require constructor arguments
             $sessionSaveHandler = $sm->get($session['save_handler']);
         }
         $sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);
         //применить валидаторы
         if (isset($session['validators'])) {
             $chain = $sessionManager->getValidatorChain();
             foreach ($session['validators'] as $validator) {
                 $validator = new $validator();
                 $chain->attach('session.validate', array($validator, 'isValid'));
             }
         }
     } else {
         //если нет конфига - возвращаем по умолчанию
         //            $sessionManager = new SessionManager();
         $sessionManager = parent::createService($services);
     }
     //установка для контейнеров
     Container::setDefaultManager($sessionManager);
     return $sessionManager;
 }