定制 mastersteelblade/discriminator 二次开发

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

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

mastersteelblade/discriminator

Composer 安装命令:

composer require mastersteelblade/discriminator

包简介

A simple package to handle basic discriminator manipulation for user management.

README 文档

README

Latest Stable Version Total Downloads License

Branch GitHub Actions Coverage
main Main Branch Coverage Status
dev Main Branch Coverage Status

About

This is a simple utility class to allow developers to implement discriminators on users, similar to Discord. This allows multiple users to share the same nickname, while allowing accounts to be tied to, for example, email addresses for uniqueness.

Installation using Composer

composer require sonata-project/google-authenticator

Usage

Discriminator is very simple to use. Below are some examples, but first, make things easier on yourself:

use Steelblade/Discriminator/Discriminator;

If you use another package that has a class of the same name, substitute the classes below with the full namespace.

Generate a discriminator

Generating a discriminator can be done in one of two ways. First, you can simply create an object without passing a parameter in.

$discriminator = new Discriminator();

As no parameter has been passed, it will generate one automatically, in a range of 0 to 9999 inclusive.

You can then, if disired, get the integer value using

$intVal = $discriminator->get();

Alternatively, to generate a discriminator without instantiating, a static method exists to return an integer value.

$discriminator = Discriminator::generate();

Loading a user from a database

Lets say a you want to display a profile page for a user, and you retrieve their information from a database.

class User {
    private $ID;
    private $emailAddress;
    public $nickname;
    public $discriminator;

    ...

    public function login($emailAddress, $password) {
        // Retrieve the user from the database and verify their password. 
        if ($successfulLogin) {
            $this->emailAddress = $databaseRow['email'];
            $this->nickname = $databaseRow['nickname'];
            $this->discriminator = new Discriminator($databaseRow['discriminator']);
        }
    }
}

The discriminator reads the numeric value, and creates itself accordingly.

Displaying a discriminator

Discriminators can be included in strings. For example:

return "The discriminator for $user->nickname is $user->discriminator";
// The discriminator for Master Steelblade is 0451

Representations of discriminators add leading zeroes to make the length consistent.

You can also retrieve the string value statically, by providing an integer value:

$integer = 47;
$discriminator = Discriminator::format($integer);
// Returns 0047 as a string

License

Discriminator is provided under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固