kodi-app/kodi-session

v0.9.1 2017-10-01 22:28 UTC

This package is not auto-updated.

Last update: 2024-09-21 01:24:46 UTC


README

此仓库包含针对 KodiApp 的不同会话实现。

安装

$ composer require kodi-app/kodi-session

配置 SessionHook

PandabaseSessionHook

PandabaseSessionHook 实现基于 Symfony 的 PdoSessionHandler。

$application->run([
    // ...
    KodiConf::HOOKS => [
        // ...
        [
            "class_name" => PandabaseSessionHook::class,
            "parameters" => [
                // Optional, you have to set it when you have more Connection instance in ConnectionManager
                "connection_name"  => "default",
                
                // Optional, 'options' parameter is same as PdoSessionHandler's 'options' parameter
                "options" => [
                    // ...
                ]
            ]
        ],
        // ...
    ],
    // ...
]);

关于 PdoSessionHandler 的详细信息请参见 此处

关于 Pandabase 的详细信息请参见 此处

配置 SessionProvider

$application->run([
    KodiConf::SERVICES => [
        SessionProvider::class
    ]
]);

如何使用 SessionProvider

/** @var Session $session */
$session = Application::get("session")

// Get username value from session (same as $_SESSION["username"]). If it doesnt exist returns with "anon".
$username = $session->get("username","anon")

// Set a new username
$new_username = "john_doe";
$session->set("username",$new_username);