Objective
#2205295: Objectify session handler converted Drupal's internal session handling functions into a PHP 5.4
SessionHandler
class.The remainder of
session.inc
are high-level, public API functions to manage user sessions.
Proposed resolution
Convert the procedural session management functions into a new
SessionManager
service.Note: The functionality of this service/class is named
SessionStorage
in Symfony (which is a complete misnomer).Properly inject the session_manager dependency into other services:
- Cookie authentication provider
- Cron
Remove
/core/includes/session.inc
.
API changes
The session management functions in /core/includes/session.inc
have been converted into a SessionManager
class, which is made available as session_manager
service now.
Drupal 7
<?php
// Force-start a session.
drupal_session_start();
// Check whether a session has been started.
drupal_session_started();
// Migrate the current session from anonymous to authenticated (or vice-versa).
drupal_session_regenerate();
// Delete the session(s) of a particular user.
drupal_session_destroy_uid($uid);
?>
Drupal 8
<?php
$session_manager = \Drupal::service('session_manager');
// Force-start a session.
$session_manager->start();
// Check whether a session has been started.
$session_manager->isStarted();
// Migrate the current session from anonymous to authenticated (or vice-versa).
$session_manager->regenerate();
// Delete the session(s) of a particular user.
$session_manager->delete($uid);
?>