예제 #1
0
 /**
  * Constructor
  *
  * @param SaveHandlerFactory $saveHandlerFactory
  * @param DeploymentConfig $deploymentConfig
  * @param string $default
  */
 public function __construct(SaveHandlerFactory $saveHandlerFactory, DeploymentConfig $deploymentConfig, $default = self::DEFAULT_HANDLER)
 {
     $saveMethod = $deploymentConfig->get(\Magento\Framework\Session\Config::PARAM_SESSION_SAVE_METHOD);
     try {
         $adapter = $saveHandlerFactory->create($saveMethod);
     } catch (SessionException $e) {
         $adapter = $saveHandlerFactory->create($default);
     }
     $this->saveHandlerAdapter = $adapter;
 }
예제 #2
0
 /**
  * Constructor
  *
  * @param SaveHandlerFactory $saveHandlerFactory
  * @param ConfigInterface $config
  * @param string $default
  */
 public function __construct(SaveHandlerFactory $saveHandlerFactory, ConfigInterface $config, $default = self::DEFAULT_HANDLER)
 {
     $saveMethod = $config->getSaveHandlerName();
     try {
         $connection = $saveHandlerFactory->create($saveMethod);
     } catch (SessionException $e) {
         $connection = $saveHandlerFactory->create($default);
         $config->setSaveHandler($default);
     }
     $this->saveHandlerAdapter = $connection;
 }
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Magento\Framework\Session\SaveHandler\Native doesn't implement \SessionHandlerInterface
  */
 public function testCreateInvalid()
 {
     $invalidSaveHandler = new \Magento\Framework\DataObject();
     $objectManager = $this->getMockBuilder('Magento\\Framework\\ObjectManager\\ObjectManager')->disableOriginalConstructor()->getMock();
     $objectManager->expects($this->once())->method('create')->willReturn($invalidSaveHandler);
     $model = new SaveHandlerFactory($objectManager, []);
     $model->create('files');
 }
예제 #4
0
 /**
  * Constructor
  *
  * @param SaveHandlerFactory $saveHandlerFactory
  * @param DeploymentConfig $deploymentConfig
  * @param string $default
  */
 public function __construct(SaveHandlerFactory $saveHandlerFactory, DeploymentConfig $deploymentConfig, $default = self::DEFAULT_HANDLER)
 {
     /**
      * Session handler
      *
      * Save handler may be set to custom value in deployment config, which will override everything else.
      * Otherwise, try to read PHP settings for session.save_handler value. Otherwise, use 'files' as default.
      */
     $defaultSaveHandler = ini_get('session.save_handler') ?: SaveHandlerInterface::DEFAULT_HANDLER;
     $saveMethod = $deploymentConfig->get(Config::PARAM_SESSION_SAVE_METHOD, $defaultSaveHandler);
     $this->setSaveHandler($saveMethod);
     try {
         $connection = $saveHandlerFactory->create($saveMethod);
     } catch (SessionException $e) {
         $connection = $saveHandlerFactory->create($default);
         $this->setSaveHandler($default);
     }
     $this->saveHandlerAdapter = $connection;
 }
 /**
  * @dataProvider createDataProvider
  */
 public function testCreate($handlers, $saveClass, $saveMethod)
 {
     $saveHandler = $this->getMock($saveClass);
     $objectManager = $this->getMock('\\Magento\\Framework\\ObjectManager\\ObjectManager', ['create'], [], '', false);
     $objectManager->expects($this->once())->method('create')->with($this->equalTo($saveClass), $this->equalTo([]))->will($this->returnValue($saveHandler));
     $model = new SaveHandlerFactory($objectManager, $handlers);
     $result = $model->create($saveMethod);
     $this->assertInstanceOf($saveClass, $result);
     $this->assertInstanceOf('\\Magento\\Framework\\Session\\SaveHandler\\Native', $result);
     $this->assertInstanceOf('\\SessionHandler', $result);
 }