定制 yii1tech/session-dummy 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yii1tech/session-dummy

最新稳定版本:1.0.1

Composer 安装命令:

composer require yii1tech/session-dummy

包简介

Provides support for Yii1 application runtime configuration

README 文档

README

Dummy Session Extension for Yii 1


This extension provides a mock for the standard Yii session, which avoids direct operations over PHP standard session.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii1tech/session-dummy

or add

"yii1tech/session-dummy": "*"

to the "require" section of your composer.json.

Usage

This extension provides a mock for the standard Yii session, which avoids direct operations over PHP standard session. It introduces \yii1tech\session\dummy\DummySession class, which does not actually store session data anywhere, except current process's memory, and avoid sending any headers to HTTP response.

This class is useful while writing unit tests, as it avoids sending headers and cookies to the StdOut.

Application configuration example:

<?php

return [
    'name' => 'Test Application',
    'components' => [
        'session' => [
            'class' => yii1tech\session\dummy\DummySession::class,
        ],
        // ...
    ],
    // ...
];

This extension may also come in handy in API development. For example: if you need to authenticate user via OAuth token, but keep tracking him in the code using \CWebUser abstraction. In this case you may switch session component "on the fly". For example:

<?php

namespace app\web\controllers;

use app\oauth\AuthUserByTokenFilter;
use CController;
use Yii;
use yii1tech\session\dummy\DummySession;

class ApiController extends CController
{
    public function init()
    {
        parent::init();
        
        Yii::app()->setComponent('session', new DummySession(), false); // mock session, so it does not send any Cookies to the API client
    }
    
    public function filters()
    {
        return [
            AuthUserByTokenFilter::class, // use custom identity to authenticate user via OAuth token inside {@see CWebUser}
            'accessControl', // now we can freely use standard "access control" filter and other features
        ];
    }
    
    public function accessRules()
    {
        return [
            // ...
        ];
    }
    
    // ...
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2023-06-13