Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NativeFileSessionHandler.php

class NativeFileSessionHandler

Native session handler using PHP's built in file storage.

@author Drak <drak@zikula.org>

Hierarchy

  • class \Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler extends \Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandler

Expanded class hierarchy of NativeFileSessionHandler

File

vendor/symfony/http-foundation/Session/Storage/Handler/NativeFileSessionHandler.php, line 19

Namespace

Symfony\Component\HttpFoundation\Session\Storage\Handler
View source
class NativeFileSessionHandler extends \SessionHandler {
    
    /**
     * @param string|null $savePath Path of directory to save session files
     *                              Default null will leave setting as defined by PHP.
     *                              '/path', 'N;/path', or 'N;octal-mode;/path
     *
     * @see https://php.net/session.configuration#ini.session.save-path for further details.
     *
     * @throws \InvalidArgumentException On invalid $savePath
     * @throws \RuntimeException         When failing to create the save directory
     */
    public function __construct(?string $savePath = null) {
        $baseDir = $savePath ??= \ini_get('session.save_path');
        if ($count = substr_count($savePath, ';')) {
            if ($count > 2) {
                throw new \InvalidArgumentException(\sprintf('Invalid argument $savePath \'%s\'.', $savePath));
            }
            // characters after last ';' are the path
            $baseDir = ltrim(strrchr($savePath, ';'), ';');
        }
        if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
            throw new \RuntimeException(\sprintf('Session Storage was not able to create directory "%s".', $baseDir));
        }
        if ($savePath !== \ini_get('session.save_path')) {
            ini_set('session.save_path', $savePath);
        }
        if ('files' !== \ini_get('session.save_handler')) {
            ini_set('session.save_handler', 'files');
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
NativeFileSessionHandler::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal