NativeSqliteSessionHandler.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
  11. /**
  12. * NativeSqliteSessionHandler.
  13. *
  14. * Driver for the sqlite session save hadlers provided by the SQLite PHP extension.
  15. *
  16. * @author Drak <drak@zikula.org>
  17. */
  18. class NativeSqliteSessionHandler extends NativeSessionHandler
  19. {
  20. /**
  21. * Constructor.
  22. *
  23. * @param string $savePath Path to SQLite database file itself.
  24. * @param array $options Session configuration options.
  25. */
  26. public function __construct($savePath, array $options = array())
  27. {
  28. if (!extension_loaded('sqlite')) {
  29. throw new \RuntimeException('PHP does not have "sqlite" session module registered');
  30. }
  31. if (null === $savePath) {
  32. $savePath = ini_get('session.save_path');
  33. }
  34. ini_set('session.save_handler', 'sqlite');
  35. ini_set('session.save_path', $savePath);
  36. $this->setOptions($options);
  37. }
  38. /**
  39. * Set any sqlite ini values.
  40. *
  41. * @see http://php.net/sqlite.configuration
  42. */
  43. protected function setOptions(array $options)
  44. {
  45. foreach ($options as $key => $value) {
  46. if (in_array($key, array('sqlite.assoc_case'))) {
  47. ini_set($key, $value);
  48. }
  49. }
  50. }
  51. }