Disciple
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.