PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/ezsession/classes/ezpsessionhandlersymfony.php

http://github.com/ezsystems/ezpublish
PHP | 154 lines | 99 code | 23 blank | 32 comment | 8 complexity | 315fce31fd8d18979b44018c15a903f1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * File containing Symfony session handler
  4. *
  5. * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  6. * @license For full copyright and license information view LICENSE file distributed with this source code.
  7. * @version //autogentag//
  8. * @package lib
  9. */
  10. /**
  11. * Symfony session handler. Basically, it let Symfony manage the session and
  12. * call the Symfony session storage when needed for very specific operation.
  13. *
  14. * @package lib
  15. * @subpackage ezsession
  16. */
  17. class ezpSessionHandlerSymfony extends ezpSessionHandler
  18. {
  19. /**
  20. * @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface
  21. */
  22. protected $storage;
  23. /**
  24. * reimp. Does not do anything to let Symfony manage the session handling
  25. */
  26. public function setSaveHandler()
  27. {
  28. // make sure eZUser does not update lastVisit on every request and only on login
  29. $GLOBALS['eZSessionIdleTime'] = 0;
  30. return true;
  31. }
  32. public function read( $sessionId )
  33. {
  34. return false;
  35. }
  36. public function write( $sessionId, $sessionData )
  37. {
  38. return false;
  39. }
  40. public function destroy( $sessionId )
  41. {
  42. if ( eZSys::isShellExecution() )
  43. {
  44. return false;
  45. }
  46. $sfHandler = $this->storage->getSaveHandler();
  47. ezpEvent::getInstance()->notify( 'session/destroy', array( $sessionId ) );
  48. if ( method_exists( $sfHandler, 'destroy' ) )
  49. {
  50. return $sfHandler->destroy( $sessionId );
  51. }
  52. return false;
  53. }
  54. public function regenerate( $updateBackendData = true )
  55. {
  56. if ( eZSys::isShellExecution() )
  57. {
  58. return false;
  59. }
  60. $oldSessionId = session_id();
  61. $this->storage->regenerate( $updateBackendData );
  62. $newSessionId = session_id();
  63. ezpEvent::getInstance()->notify( 'session/regenerate', array( $oldSessionId, $newSessionId ) );
  64. if ( $updateBackendData )
  65. {
  66. $db = eZDB::instance();
  67. $escOldKey = $db->escapeString( $oldSessionId );
  68. $escNewKey = $db->escapeString( $newSessionId );
  69. $escUserID = $db->escapeString( eZSession::userID() );
  70. eZSession::triggerCallback( 'regenerate_pre', array( $db, $escNewKey, $escOldKey, $escUserID ) );
  71. eZSession::triggerCallback( 'regenerate_post', array( $db, $escNewKey, $escOldKey, $escUserID ) );
  72. }
  73. return true;
  74. }
  75. public function gc( $maxLifeTime )
  76. {
  77. if ( eZSys::isShellExecution() )
  78. {
  79. return false;
  80. }
  81. ezpEvent::getInstance()->notify( 'session/gc', array( $maxLifeTime ) );
  82. $db = eZDB::instance();
  83. eZSession::triggerCallback( 'gc_pre', array( $db, $maxLifeTime ) );
  84. $sfHandler = $this->storage->getSaveHandler();
  85. if ( method_exists( $sfHandler, 'gc' ) )
  86. {
  87. $sfHandler->gc( $maxLifeTime );
  88. }
  89. eZSession::triggerCallback( 'gc_post', array( $db, $maxLifeTime ) );
  90. return false;
  91. }
  92. public function cleanup()
  93. {
  94. }
  95. public function deleteByUserIDs( array $userIDArray )
  96. {
  97. }
  98. static public function count()
  99. {
  100. return -1;
  101. }
  102. static public function hasBackendAccess()
  103. {
  104. }
  105. static public function dbRequired()
  106. {
  107. return false;
  108. }
  109. /**
  110. * Set the storage handler defined in Symfony.
  111. *
  112. * @param \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface $storage
  113. */
  114. public function setStorage( $storage )
  115. {
  116. $this->storage = $storage;
  117. }
  118. /**
  119. * Let Symfony starts the session
  120. *
  121. * @return bool
  122. */
  123. public function sessionStart()
  124. {
  125. if ( $this->storage && !$this->storage->isStarted() )
  126. {
  127. $this->storage->start();
  128. }
  129. return true;
  130. }
  131. }