Take control of your users in PHP

Overview

Disciple

PHP from Packagist Latest Version Total Downloads Build Status PHPStan License

Take control of your users

Installation

Install via Composer:

composer require decodelabs/disciple

PHP version

Please note, the final v1 releases of all Decode Labs libraries will target PHP8 or above.

Current support for earlier versions of PHP will be phased out in the coming months.

Usage

Importing

Disciple uses Veneer to provide a unified frontage under DecodeLabs\Disciple. You can access all the primary functionality via this static frontage without compromising testing and dependency injection.

Implementation

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

namespace DecodeLabs\Disciple;

interface Adapter
{
    public function isLoggedIn(): bool;

    public function getIdentity(): ?string;
    public function getProfile(): Profile;

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

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

Your adapter should be registered during your app's bootstrap process:

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

Disciple::setAdapter(new DiscipleAdapter(
    $myUserManager
));

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

use DecodeLabs\Disciple;

if(Disciple::isLoggedIn()) {
    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.

namespace DecodeLabs\Disciple;

interface Profile
{
    public function getId(): ?string;
    public function getEmail(): ?string;
    public function getFullName(): ?string;
    public function getFirstName(): ?string;
    public function getSurname(): ?string;
    public function getNickName(): ?string;

    public function getRegistrationDate(): ?DateTime;
    public function getLastLoginDate(): ?DateTime;

    public function getLanguage(): ?string;
    public function getCountry(): ?string;
    public function getTimeZone(): ?string;

    public function getSignifiers(): array;
}

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

use DecodeLabs\Disciple;

if(Disciple::isLoggedIn()) {
    echo 'Hello '.Disciple::getFullName();
} else {
    echo 'You should probably log in first';
}

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.

You might also like...
Opensource IPTV control panel

OpenSource IPTV copy .env.example to .env and edit to your environment composer install --no-dev php artisan sriptv:init Docker build: docker build .

This Statamic addon allows you to modify the tags rendered by the Bard fieldtype, giving you full control over the final HTML.

Bard Mutator This Statamic addon allows you to modify the tags rendered by the Bard fieldtype, giving you full control over the final HTML. You can ad

Silverstripe-tinytidy - Control which styles are available in TinyMCE's style dropdown menu and what elements they can be applied to
Silverstripe-tinytidy - Control which styles are available in TinyMCE's style dropdown menu and what elements they can be applied to

TinyTidy for SilverStripe This module mainly serves as an example of how to customise the 'styles' dropdown menu in the TinyMCE editor to control whic

Magento 2 GDPR extension Free by Magepow helps websites comply with GDPR regulations, allowing customers to control personal data and avoid penalties.

Magento 2 GDPR extension Free by Magepow helps websites comply with GDPR regulations, allowing customers to control personal data and avoid penalties.

API server and modernized control panel for PocketMine servers.

WebConsole API server and modernized control panel for PocketMine servers. The WebConsole plugin provides an HTTP API server that can be extended with

Allow your users to login with their Ethereum wallet.

Allow your users to login with their Ethereum wallet Allow your users to link their Ethereum wallet to their account to skip entering their login cred

Compare your Github followers vs following users

followers-vs-following Compare your Github followers vs following users https://docs.github.com/en/rest/reference/users The code only queries 3k follo

The best announcer for PocketMine-MP 4.0 servers, make messages for your users very easily
The best announcer for PocketMine-MP 4.0 servers, make messages for your users very easily

BroadcastACM The best announcer for PocketMine-MP 4.0 servers, make messages for your users very easily. Make the best announcements for your server w

A Laravel 9 package that allows you enforce security of your artisan commands by authenticating users before running.

Introduction This package allows you as a developer to restrict who can and cannot run artisan commands, especially in a production environment. For e

Releases(v0.3.5)
Owner
Decode Labs
Decode Labs
LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

Teniola Fatunmbi 2 Aug 22, 2022
Shortest Path - have a function ShortestPath (strArr) take strArr which will be an array of strings which models a non-looping Graph.

Have the function ShortestPath(strArr) take strArr which will be an array of strings which models a non-looping Graph

null 1 Feb 5, 2022
Silverstripe-masquerade - SilverStripe module to allow users to "masquerade" as other users

SilverStripe Masquerade Module About This module is designed to allow an Administrator to "login" as another "Member" without changing their password

Daniel Hensby 14 Apr 14, 2022
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Ry-Zen 7 Aug 21, 2022
Core - ownCloud gives you freedom and control over your own data.

ownCloud Core ownCloud gives you freedom and control over your own data. A personal cloud which runs on your own server. Why is this so awesome? ?? Ac

ownCloud 7.9k Jan 4, 2023
Keep control over the complexity of your methods by checking that they do not have too many arguments.

php arguments detector The ideal number of arguments for a function is zero. ~ Robert C. Martin Keep control over the complexity of your methods by ch

DeGraciaMathieu 13 Dec 26, 2022
Talkino allows you to integrate multi social messengers and contact into your website and enable your users to contact you using multi social messengers' accounts.

Talkino Welcome to our GitHub Repository Talkino is a click to chat plugin to show your agents’ multiple social messengers, phone and emails on the ch

Traxconn 2 Sep 21, 2022
Rafel is Remote Access Tool Used to Control Victims Using WebPanel With More Advance Features..

Rafel is Remote Access Tool Used to Control Victims Using WebPanel With More Advance Features..

swagkarna 690 Dec 28, 2022
Source control integration plugin framework for MantisBT, including support for Github, Gitlab, Bitbucket, Gitweb, Cgit, Subversion, Mercurial and more

Source control integration plugin framework for MantisBT, including support for Github, Gitlab, Bitbucket, Gitweb, Cgit, Subversion, Mercurial and more

MantisBT Community Plugins 175 Sep 3, 2022
Control all text in multiple file bad words filter with worps

About Worps | PHP! Control all text in multiple file bad words filter with worps If you try online Click What to do use for worps Create new object Wo

null 1 Dec 30, 2021