Skip to content

Commit

Permalink
afup#1415 Session in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Jan 6, 2024
1 parent 82d4e55 commit 9e33fec
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 18 deletions.
5 changes: 2 additions & 3 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ framework:
default_locale: "%locale%"
trusted_hosts: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
storage_id: session.storage.php_bridge
handler_id: ~
# https://symfony.com/doc/4.x/session/database.html#store-sessions-in-a-relational-database-mariadb-mysql-postgresql
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
fragments: ~
http_method_override: true
assets: ~
Expand Down
6 changes: 6 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ services:
_defaults:
public: true

Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
public: false
arguments:
- 'mysql:host=%database_host%;port=%database_port%;dbname=%database_name%'
- { db_username: '%database_user%', db_password: '%database_password%' }

AppBundle\Controller\Event\:
resource: '../../sources/AppBundle/Controller/Event/*'
autowire: true
Expand Down
20 changes: 20 additions & 0 deletions db/migrations/20240106213200_sessions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Phinx\Migration\AbstractMigration;

class Sessions extends AbstractMigration
{
public function change()
{
$sql = <<<EOF
CREATE TABLE `sessions` (
`sess_id` VARBINARY(128) NOT NULL PRIMARY KEY,
`sess_data` BLOB NOT NULL,
`sess_lifetime` INTEGER UNSIGNED NOT NULL,
`sess_time` INTEGER UNSIGNED NOT NULL,
INDEX `sessions_sess_lifetime_idx` (`sess_lifetime`)
) COLLATE utf8mb4_bin, ENGINE = InnoDB;
EOF;
$this->execute($sql);
}
}
4 changes: 0 additions & 4 deletions htdocs/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

session_start();

/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../vendor/autoload.php';
Debug::enable();
Expand All @@ -34,8 +32,6 @@
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../vendor/autoload.php';

session_start();

$kernel = new AppKernel('prod', false);
}

Expand Down
2 changes: 0 additions & 2 deletions htdocs/include/prepend.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Initialisation
ob_start();

session_start();

// Inclusion de l'autoload de composer
require_once dirname(__FILE__) . '/../../vendor/autoload.php';

Expand Down
4 changes: 0 additions & 4 deletions htdocs/pages/planete/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

session_start();

/** @var ClassLoader $loader */
$loader = require __DIR__.'/../../../vendor/autoload.php';
Debug::enable();
Expand All @@ -43,8 +41,6 @@
/** @var ClassLoader $loader */
$loader = require __DIR__.'/../../../vendor/autoload.php';

session_start();

$kernel = new PlaneteAppKernel('prod', false);
}

Expand Down
4 changes: 2 additions & 2 deletions planete/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ framework:
default_locale: "%locale%"
trusted_hosts: ~
session:
storage_id: session.storage.php_bridge
handler_id: ~
# https://symfony.com/doc/4.x/session/database.html#store-sessions-in-a-relational-database-mariadb-mysql-postgresql
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
fragments: ~
http_method_override: true
assets: ~
Expand Down
6 changes: 6 additions & 0 deletions planete/app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ services:
autowire: true
autoconfigure: true

Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
public: false
arguments:
- 'mysql:host=%database_host%;port=%database_port%;dbname=%database_name%'
- { db_username: '%database_user%', db_password: '%database_password%' }

AppBundle\LegacyModelFactory: ~

PlanetePHP\:
Expand Down
3 changes: 0 additions & 3 deletions sources/Afup/Bootstrap/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
if (ob_get_level() === 0) {
ob_start();
}
if (session_status() === PHP_SESSION_NONE) {
session_start();
}

// mise à jour des paramètrage PHP en fonction de la configuration

Expand Down

0 comments on commit 9e33fec

Please sign in to comment.