00f100/fcphp-sconsole

该软件包最新版本(0.1.1)没有可用的许可证信息。

软件包安全控制台请求

安装: 56

依赖: 1

建议者: 0

安全: 0

星级: 1

关注者: 1

分支: 1

开放问题: 0

类型:软件包

0.1.1 2018-08-04 15:56 UTC

This package is auto-updated.

Last update: 2024-09-18 05:59:38 UTC


README

用于操作控制台用户认证的库

Build Status codecov Total Downloads

如何安装

Composer

$ composer require 00f100/fcphp-sconsole

或在 composer.json 中添加

{
    "require": {
        "00f100/fcphp-sconsole": "*"
    }
}

如何使用

<?php

use FcPhp\SConsole\Facades\SConsoleFacade;
use FcPhp\SConsole\Interfaces\ISCEntity;

// Init instance
$instance = SConsoleFacade::getInstance();

// Configure Callback
$instance->authCallback(function(ISCEntity $entity, array $params, array $server) {

    // Your validate code here...

    $entity->setType('user');
    // $entity->setType('admin');
    // default: $entity->setType('guest');
    $entity->setName('any name');
    return $entity;
});

// FcPhp\SConsole\Interfaces\ISCEntity
$SecurityConsoleEntity = $instance->get();

// Print: any name
echo $SecurityConsoleEntity->getName();

FcPhp\SConsole\Interfaces\ISCEntity

interface ISCEntity
    {
        /**
         * Method to construct instance of Security Entity
         *
         * @param int $expires Timestamp expires Security Entity
         * @return void
         */
        public function __construct(int $expires = 84000);

        /**
         * Method to set Id of login
         *
         * @param string $id Id of login
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setId(string $id) :ISEntity;

        /**
         * Method to get Id of login
         *
         * @return string|null
         */
        public function getId();

        /**
         * Method to set Name of login
         *
         * @param string $name Name of login
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setName(string $name) :ISEntity;

        /**
         * Method to get Name of login
         *
         * @return string|null
         */
        public function getName();

        /**
         * Method to set E-mail of login
         *
         * @param string $email E-mail of login
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setEmail(string $email) :ISEntity;
        /**
         * Method to get E-mail of login
         *
         * @return string|null
         */
        public function getEmail();

        /**
         * Method to set User name of login
         *
         * @param string $username User name of login
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setUsername(string $username) :ISEntity;
        /**
         * Method to get User name of login
         *
         * @return string|null
         */
        public function getUsername();

        /**
         * Method to set Type of login
         *
         * @param string|int $type Type of login
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setType($type) :ISEntity;
        /**
         * Method to get Type of login
         *
         * @return string
         */
        public function getType() :string;

        /**
         * Method to set Permissions of login
         *
         * @param array $permissions Permissions of login
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setPermissions(array $permissions) :ISEntity;
        /**
         * Method to get Permissions of login
         *
         * @return array
         */
        public function getPermissions() :array;
        /**
         * Method to check if have access to permission
         *
         * @param string $permission Permission to check
         * @return bool
         */
        public function check(string $permission) :bool;

        /**
         * Method to set Custom data of login
         *
         * @param string $key Key to save content
         * @param array|string $customData Data to save
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setCustomData(string $key, $customData) :ISEntity;
        /**
         * Method to get Custom data of login
         *
         * @param string|null $key Key to find content
         * @return array|null
         */
        public function getCustomData(string $key = null);

        /**
         * Method to set Errors of login
         *
         * @param string $message Message of error
         * @return cPhp\SHttp\Interfaces\ISEntity
         */
        public function setError(string $message) :ISEntity;

        /**
         * Method to get Errors of login
         *
         * @return array
         */
        public function getError() :array;
        
        /**
         * Method to check if have errors in login
         *
         * @return bool
         */
        public function haveErrors() :bool;

        /**
         * Method to check if this Security Entity has expired
         *
         * @return bool
         */
        public function isExpired() :bool;
    }