mastersteelblade/discriminator 问题修复 & 功能扩展

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

邮箱: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
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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