PHP code example of dasprid / helios

1. Go to this page and download the library: Download dasprid/helios 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/ */

    

dasprid / helios example snippets



return (new DASPRiD\Helios\ConfigProvider())->__invoke();


use DASPRiD\Helios\Identity\IdentityLookupInterface;
use DASPRiD\Helios\Identity\LookupResult;

class MyIdentityLookup implements IdentityLookupInterface
{
    public function lookup($subject) : LookupResult
    {
        // Pseudo-code here
        if ($this->repository->has($subject)) {
            return LookupResult::fromIdentity($this->repository->get($subject));
        }

        return LookupResult::invalid();
    }
}


return [
    'helios' => [
        // ...
        'identity_lookup_id' => MyIdentityLookup::class,
    ],
];


class MySignIn
{
    /**
     * @var \DASPRiD\Helios\IdentityCookieManager
     */
    private $identityCookieManager;

    public function __invoke()
    {
        // Verify the user

        if ($userIsValid) {
            $response = new Zend\Diactoros\Response\RedirectResponse('/go/somewhere');
            return $this->identityCookieManager->injectCookie(
                $response,
                $user->getId(),
                ! $rememberMeSelected
            );
        }

        // Do some error response here
    }
}


class MySignOut
{
    /**
     * @var \DASPRiD\Helios\IdentityCookieManager
     */
    private $identityCookieManager;

    public function __invoke()
    {
        $response = new Zend\Diactoros\Response\RedirectResponse('/go/somewhere');
        return $this->identityCookieManager->expireCookie($response);
    }
}


use DASPRiD\Helios\IdentityMiddleware;
use Psr\Http\Message\ServerRequestInterface;

class SomeOtherMiddleware
{
    public function __invoke(ServerRequestInterface $request)
    {
        $user = $request->getAttribute(IdentityMiddleware::IDENTITY_ATTRIBUTE);
    }
}