ray/aura-session-module

Aura Session 模块,适用于 Ray.Di

1.2.2 2024-06-28 11:17 UTC

This package is auto-updated.

Last update: 2024-08-28 13:19:53 UTC


README

Continuous Integration

Aura.Session 模块,为 Ray.Di

安装

Composer 安装

$ composer require ray/aura-session-module

模块安装

use Ray\Di\AbstractModule;
use Ray\AuraSessionModule\AuraSessionModule;

class AppModule extends AbstractModule
{
    protected function configure(): void
    {
        $this->install(new AuraSessionModule);
    }
}

使用方法

use Aura\Session\Session;
use MyVendor\MyPackage\MyClass;

class Index extends ResourceObject
{
    public function __construct(
        private readonly Session $session
    ) {}
    
    public function onGet() : static
    {
        // get a _Segment_ object
        $segment = $this->session->getSegment(MyClass::class);
        
        // try to get a value from the segment;
        // if it does not exist, return an alternative value
        echo $segment->get('foo'); // null
        echo $segment->get('baz', 'not set'); // 'not set'
    }
}

了解更多关于 Aura.Session 的信息。