1. Go to this page and download the library: Download laasti/warden 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/ */
laasti / warden example snippets
$pdo = new PDO($dsn, $user, $password);
//By default the repository looks for a table "users" with columns: id, email, password, roles, permissions
//Roles and permissions are comma-delimited.
$repo = new Laasti\Warden\Repositories\PdoUserRepository($pdo);
$warden = new Laasti\Warden\Warden();
//API
$warden->admit($identifier, $password); //Logs in user matching credentials
$warden->isAdmitted(); //User is logged in
$warden->couldBeAdmitted($identifier, $password); //Checks if user could be logged in
$warden->admitUser($user); //Logs in provided user, useful to bypass authentication
$warden->currentUser(); //Logged in user, instance of GuestUser if none
$warden->dismiss(); //Logs out current user
$warden->grantAccess($roleOrPermission); //Check for role or permission in current user
$warden->grantAccessByPermission($permission); // Grant access if user matches permission
$warden->grantAccessByPermissions($permissions); // Grant access if user matches all permissions
$warden->grantAccessByRole($role); // Grant access if user matches role
$warden->grantAccessByRoles($roles); // Grant access if user matches all roles
$warden->getHasher()->hash($password); //Get a hash for a password
//Using Roles Dictionary
//Roles can inherit permissions by default, to assign permissions to roles
//you need to define a roles dictionary using an array
$dictionary = [
'ROLE' => ['permission', 'permission2']
];
$warden->setRolesDictionary($dictionary);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.