1. Go to this page and download the library: Download preflow/auth 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/ */
use Preflow\Auth\Authenticatable;
use Preflow\Auth\AuthenticatableTrait;
use Preflow\Data\Model;
use Preflow\Data\Attributes\{Entity, Id, Field};
use Preflow\Data\Transform\JsonTransformer;
#[Entity(table: 'users', storage: 'default')]
final class User extends Model implements Authenticatable
{
use AuthenticatableTrait;
#[Id] public string $uuid = '';
#[Field(searchable: true)] public string $email = '';
#[Field] public string $passwordHash = '';
#[Field(transform: JsonTransformer::class)] public array $roles = [];
#[Field] public ?string $createdAt = null;
}
use Preflow\Routing\Attributes\{Route, Get, Middleware};
use Preflow\Auth\Http\AuthMiddleware;
#[Route('/dashboard')]
#[Middleware(AuthMiddleware::class)]
final class DashboardController
{
#[Get('/')]
public function index(ServerRequestInterface $request): ResponseInterface
{
$user = $request->getAttribute(Authenticatable::class);
// ...
}
}
use Preflow\Auth\{GuardInterface, Authenticatable};
use Psr\Http\Message\ServerRequestInterface;
final class LdapGuard implements GuardInterface
{
public function user(ServerRequestInterface $request): ?Authenticatable { /* ... */ }
public function validate(array $credentials): bool { /* ... */ }
public function login(Authenticatable $user, ServerRequestInterface $request): void { /* ... */ }
public function logout(ServerRequestInterface $request): void { /* ... */ }
}
use Preflow\Testing\AuthTestHelpers;
final class DashboardTest extends TestCase
{
use AuthTestHelpers;
public function test_dashboard_oard'));
// $request now has Authenticatable attribute set
}
}