charlesportwoodii / yii2-psr7-bridge

A PSR7 Bridge and PSR-15 adapter for Yii2
BSD 3-Clause "New" or "Revised" License
110 stars 20 forks source link

Ability to disable sessions #20

Closed valentin-pazushko closed 5 months ago

valentin-pazushko commented 9 months ago

Hi! How fully disable sessions (using authclient with REST)? It always sends cookie. https://github.com/charlesportwoodii/yii2-psr7-bridge/blob/94c3c461a059541c4bc5e489b657c5f96bd62c75/src/web/Application.php#L115-L132

charlesportwoodii commented 9 months ago

The session component is auto-loaded you don't define your own: https://github.com/charlesportwoodii/yii2-psr7-bridge/blob/94c3c461a059541c4bc5e489b657c5f96bd62c75/src/web/Application.php#L236. It's the same code that is in yii\web\Application: https://github.com/yiisoft/yii2/blob/master/framework/web/Application.php#L193.

Since it's just a Yii2 component, you can just define your own Session class that implements Component implements \IteratorAggregate, \ArrayAccess, \Countable and set it in your configuration file.

return [
    'components' => [
        'session' => [
            'class' => 'NullSession',
        ],
    ],
];

Basically copy yii\web\Session (https://www.yiiframework.com/doc/api/2.0/yii-web-session) and overwrite all the methods so they don't do anything.