PHP code example of decodelabs / disciple

1. Go to this page and download the library: Download decodelabs/disciple library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

decodelabs / disciple example snippets


namespace DecodeLabs\Disciple;

interface Adapter
{
    public ?string $identity { get; }
    public Profile $profile { get; }
    public Client $client { get; }

    public bool $loggedIn { get; }

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

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

Monarch::getKingdom()->container->set(
    Adapter::class,
    new DiscipleAdapter($myUserManager)
);

$disciple = Monarch::getService(Disciple::class);

if($disciple->loggedIn) {
    echo 'Yay, you\'re logged in';
} else {
    echo 'Boo, nobody loves me';
}

interface Profile
{
    public ?string $id { get; }
    public ?string $email { get; }
    public ?string $fullName { get; }
    public ?string $firstName { get; }
    public ?string $surname { get; }
    public ?string $nickName { get; }

    public ?DateTime $registrationDate { get; }
    public ?DateTime $lastLoginDate { get; }

    public ?string $language { get; }
    public ?string $country { get; }
    public ?string $timeZone { get; }

    /**
     * @var list<string>
     */
    public array $signifiers { get; }
}

if($disciple->loggedIn) {
    echo 'Hello ' . $disciple->fullName;
} else {
    echo 'You should probably log in first';
}

interface Client
{
    public string $protocol { get; }
    public Ip $ip { get; }
    public string $ipString { get; }
    public ?string $agent { get; }
}

if($disciple->isA('admin')) {
    echo 'You can see the fun stuff';
} else {
    echo 'You should go home now';
}