decodelabs/disciple 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

decodelabs/disciple

最新稳定版本:v0.6.1

Composer 安装命令:

composer require decodelabs/disciple

包简介

Take control of your users

关键字:

README 文档

README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

Take control of your users

Disciple offers a set of simple interfaces that allows third party code to define reliable entry points to user state and data.

Installation

This package requires PHP 8.4 or higher.

Install via Composer:

composer require decodelabs/disciple

Usage

Implementation

An implementation of Disciple revolves around an Adapter - this acts as the primary mediator between the Disciple service and your system's user management infrastructure.

namespace DecodeLabs\Disciple;

interface Adapter
{
    public ?string $identity { get; }
    public Profile $profile { get; }
    public Client $client { get; }

    public bool $loggedIn { get; }

    public function isA(
        string ...$signifiers
    ): bool;
}

Your adapter should be supplied during instantiation of the Disciple service. This is typically done in your app's bootstrap process via your service container:

use DecodeLabs\Disciple;
use DecodeLabs\Disciple\Adapter;
use DecodeLabs\Monarch;
use My\App\DiscipleAdapter;

Monarch::getKingdom()->container->set(
    Adapter::class,
    new DiscipleAdapter($myUserManager)
);

$disciple = Monarch::getService(Disciple::class);

Then at any future point, queries can be made against the current user:

if($disciple->loggedIn) {
    echo 'Yay, you\'re logged in';
} else {
    echo 'Boo, nobody loves me';
}

Profile

A registered Adapter should be able to provide an instance of a Profile, representing core data about the current user, such as name, email address, locale, etc.

interface Profile
{
    public ?string $id { get; }
    public ?string $email { get; }
    public ?string $fullName { get; }
    public ?string $firstName { get; }
    public ?string $surname { get; }
    public ?string $nickName { get; }

    public ?DateTime $registrationDate { get; }
    public ?DateTime $lastLoginDate { get; }

    public ?string $language { get; }
    public ?string $country { get; }
    public ?string $timeZone { get; }

    /**
     * @var list<string>
     */
    public array $signifiers { get; }
}

The service can interface directly with this profile information, allowing quick access of user data:

if($disciple->loggedIn) {
    echo 'Hello ' . $disciple->fullName;
} else {
    echo 'You should probably log in first';
}

Client

An Adapter should also be able to provide a Client object which can report details of how a user is interfacing with the system.

Currently, that entails the following, but with more to follow in future versions:

interface Client
{
    public string $protocol { get; }
    public Ip $ip { get; }
    public string $ipString { get; }
    public ?string $agent { get; }
}

Signifiers

The Disciple interfaces define the concept of signifiers - string keys that users can be categorised and identified by.

It is the responsibility of the Adapter implementation to define how signifiers are stored and distributed, however the definition of this interface allows for a powerful, quick access mechanism for high level structures in your application.

if($disciple->isA('admin')) {
    echo 'You can see the fun stuff';
} else {
    echo 'You should go home now';
}

Licensing

Disciple is licensed under the MIT License. See LICENSE for the full license text.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固