承接 genai/session 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

genai/session

Composer 安装命令:

composer require genai/session

包简介

Session component with pluggable storage: native files (default), a project file dir (cache/session), or a database (PDO). A small Session API over native PHP sessions; a SessionStore save-handler decides where the data lives. Driver chosen from the [session] config group. PHP 5.3-safe runtime.

README 文档

README

A session component with pluggable storage. A small Session API over native PHP sessions; a SessionStore save-handler decides where the data lives:

driver store use it for
default native files single server, simplest
file FileStore project-local files (cache/session/)
database PdoStore multiple servers (shared sessions table)

The cookie, session id, and GC stay native — only the read/write target changes.

API

$session->set('uid', 7);
$uid = $session->get('uid', 0);
$session->has('uid'); $session->remove('uid'); $session->pull('once');
$session->flash('msg', 'Saved!');       // available on the NEXT request
$msg = $session->getFlash('msg');
$session->regenerate();                  // on login (anti-fixation)
$session->destroy();                     // on logout

Starts lazily on first use, so responses that never touch the session set no cookie.

Config ([session] group, optional)

[session]
driver   = file          ; default | file | database
name     = KIDSAFE
lifetime = 0             ; cookie seconds (0 = until browser close)
path     = cache/session ; driver=file
table    = sessions      ; driver=database

Wiring (one bean)

The factory picks the store from config; the app decides whether it has a PDO to pass:

#[Configuration]
class SessionConfig
{
    #[Bean(\GenAI\Session\Session::class)]
    public function session(\GenAI\Session\Bundle\SessionProperty $cfg, \PDO $pdo)
    {
        return \GenAI\Session\SessionFactory::build($cfg, $pdo);   // omit $pdo if no DB
    }
}

Then inject GenAI\Session\Session anywhere and drop manual session_start().

Notes

  • SessionProperty auto-registers (the package declares extra.genai.scan); just require genai/session.
  • PHP 5.3 has no SessionHandlerInterface, so this uses the 6-callback save-handler form plus a session_write_close shutdown hook (so custom stores flush before objects are destroyed).
  • SameSite isn't set on the cookie (needs PHP 7.3+); httponly is always on, secure is auto on HTTPS.
  • database needs ext-pdo. The table is created on first use; UPDATE-then-INSERT keeps it SQLite/MySQL-portable.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 2

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固