snicco/session-bundle

v2.0.0-beta.9 2024-09-07 14:27 UTC

README

codecov Psalm Type-Coverage Psalm level PhpMetrics - Static Analysis PHP-Versions

WordPress 扩展将 snicco/session 集成到基于 snicco/kernel 的应用程序中。

此扩展需要 snicco/http-routing-bundle

安装

composer install snicco/session-bundle

配置

有关可用的配置选项,请参阅 config/session.php

如果您的配置目录中没有此文件,则在开发模式下首次启动内核时将复制默认配置。

SessionBundle 添加到您的 bundles.php 配置文件中。

<?php
// /path/to/configuration/bundles.php

use Snicco\Bundle\Session\SessionBundle;

return [
    
    'bundles' => [
        Snicco\Component\Kernel\ValueObject\Environment::ALL => [
           SessionBundle::class
        ]   
    ]   
];

用法

此扩展包含多个管理会话生命周期的 中间件

建议在 HttpRoutingBundlemiddleware 配置中配置会话中间件,如下所示

//path/to/config/middleware.php
use Snicco\Bundle\HttpRouting\Option\MiddlewareOption;
use Snicco\Bundle\Session\Middleware\AllowMutableSessionForReadVerbs;
use Snicco\Bundle\Session\Middleware\SaveResponseAttributes;
use Snicco\Bundle\Session\Middleware\SessionNoCache;
use Snicco\Bundle\Session\Middleware\ShareSessionWithViews;
use Snicco\Bundle\Session\Middleware\StatefulRequest;

return [

    MiddlewareOption::GROUPS => [
        'stateful' => [
            StatefulRequest::class,
            ShareSessionWithViews::class,
            SaveResponseAttributes::class,
//            SessionNoCache::class, optional
        ]   
    ],
    MiddlewareOption::ALIASES => [
        'session-allow-write' => AllowMutableSessionForReadVerbs::class,
        'session-no-cache' => SessionNoCache::class,
    ]
];

会话可以在 PSR-7 请求上访问

// inside a controller or middleware
use Snicco\Component\Session\ImmutableSession;
use Snicco\Component\Session\MutableSession;

$request->getAttribute(ImmutableSession::class);

// Only for unsafe request methods or if allowed explicitly for read requests.
$request->getAttribute(MutableSession::class);

贡献

此存储库是 Snicco 项目 开发存储库的只读分支。

以下是您如何贡献的方法.

报告问题和发送拉取请求

请在 Snicco monorepo 中报告问题。

安全

如果您在 BetterWPCache 中发现安全漏洞,请遵循我们的 披露程序