定制 piko/user 二次开发

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

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

piko/user

Composer 安装命令:

composer require piko/user

包简介

A lightweight user session manager to login/logout and retrieve user identity.

README 文档

README

build Coverage Status

A lightweight user session manager to login/logout, check permissions and retrieve user identity between sessions.

Installation

It's recommended that you use Composer to install Piko User.

composer require piko/user

Usage

Basic exemple:

require 'vendor/autoload.php';

use Piko\User;
use Piko\User\IdentityInterface;

// Define first your user identity class
class Identity implements IdentityInterface
{
    private static $users = [
        1 => 'paul',
        2 => 'pierre',
    ];

    public $id;
    public $username;

    public static function findIdentity($id)
    {
        if (isset(static::$users[$id])) {
            $user = new static();
            $user->id = $id;
            $user->username = static::$users[$id];

            return $user;
        }

        return null;
    }

    public function getId()
    {
        return $this->id;
    }
}

$user = new User([
    'identityClass' => Identity::class,
    'checkAccess' => function($id, $permission) {
        return $id == 1 && $permission == 'test';
    }
]);

// Login

$user->login(Identity::findIdentity(1));

if (!$user->isGuest()) {
    echo $user->getIdentity()->username; // paul
}

if ($user->can('test')) {
    echo 'I can test';
}

$user->logout();

if ($user->isGuest()) {
    var_dump($user->getIdentity()); // null
    echo 'Not Authenticated';
}

if (!$user->can('test')) {
    echo 'I cannot test';
}

Advanced example: See UserTest.php

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2021-09-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固