master

laravel/framework

Last updated at: 29/12/2023 09:25

NullSessionHandler.php

TLDR

This file contains the implementation of the NullSessionHandler class which acts as a placeholder for session handling when sessions are disabled or not used.

Methods

open

This method is called when the session needs to be opened. It receives the save path and session name as parameters. In this implementation, the method always returns true indicating that the session is successfully opened.

close

This method is called when the session needs to be closed. It has no parameters and always returns true indicating that the session is successfully closed.

read

This method is called when the session data needs to be retrieved. It receives the session ID as a parameter and always returns an empty string, indicating that there is no session data.

write

This method is called when the session data needs to be stored. It receives the session ID and data as parameters. In this implementation, the method always returns true, indicating that the session data is successfully stored.

destroy

This method is called when the session needs to be destroyed. It receives the session ID as a parameter. In this implementation, the method always returns true, indicating that the session is successfully destroyed.

gc

This method is called when the session garbage collection process is executed. It receives the session lifetime as a parameter and always returns 0, indicating that no session data is garbage collected.

<?php

namespace Illuminate\Session;

use SessionHandlerInterface;

class NullSessionHandler implements SessionHandlerInterface
{
    /**
     * {@inheritdoc}
     *
     * @return bool
     */
    public function open($savePath, $sessionName): bool
    {
        return true;
    }

    /**
     * {@inheritdoc}
     *
     * @return bool
     */
    public function close(): bool
    {
        return true;
    }

    /**
     * {@inheritdoc}
     *
     * @return string
     */
    public function read($sessionId): string
    {
        return '';
    }

    /**
     * {@inheritdoc}
     *
     * @return bool
     */
    public function write($sessionId, $data): bool
    {
        return true;
    }

    /**
     * {@inheritdoc}
     *
     * @return bool
     */
    public function destroy($sessionId): bool
    {
        return true;
    }

    /**
     * {@inheritdoc}
     *
     * @return int
     */
    public function gc($lifetime): int
    {
        return 0;
    }
}