DbalSessionHandlerSchema.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Bridge\Doctrine\HttpFoundation;
  11. use Doctrine\DBAL\Schema\Schema;
  12. /**
  13. * DBAL Session Storage Schema.
  14. *
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. final class DbalSessionHandlerSchema extends Schema
  18. {
  19. private $tableName;
  20. public function __construct($tableName = 'sessions')
  21. {
  22. parent::__construct();
  23. $this->tableName = $tableName;
  24. $this->addSessionTable();
  25. }
  26. public function addToSchema(Schema $schema)
  27. {
  28. foreach ($this->getTables() as $table) {
  29. $schema->_addTable($table);
  30. }
  31. }
  32. private function addSessionTable()
  33. {
  34. $table = $this->createTable($this->tableName);
  35. $table->addColumn('sess_id', 'string');
  36. $table->addColumn('sess_data', 'text')->setNotNull(true);
  37. $table->addColumn('sess_time', 'integer')->setNotNull(true)->setUnsigned(true);
  38. $table->setPrimaryKey(array('sess_id'));
  39. }
  40. }