Multi Adapter
This adapter lets you authenticate off more than one adapter. Authentication will take place on each adapter in the order they where added until 1) authentication returns true, or 2) there are no more adapters.
Basic example
<?php
use Vespula\Auth\Auth;
use Vespula\Auth\Session\Session;
use Vespula\Auth\Adapter\Text;
use Vespula\Auth\Adapter\Sql;
use Vespula\Auth\Adapter\Multi;
$passwordfile = '/path/to/.htpasswd';
$textAdapter = new Text($passwordfile);
$textAdapter->setUserdata([
'juser'=>[
'fullname'=>'Joe User',
'email'=>'juser@example.com'
]
]);
$dsn = 'mysql:dbname=mydatabase;host=localhost';
$pdo = new \PDO($dsn, 'dbuser', '********');
// $cols array must have a 'username' and 'password' element. You can use an alias if needed. See below.
// This data (except username and password) will populate the `getUserdata()` array
$cols = [
'username',
'password',
'fullname',
'email'
];
$from = 'user';
$where = 'active=1'; // optional
$sqlAdapter = new Sql($pdo, $from, $cols, $where);
$session = new Session();
$multiAdapter = new Multi();
$multiAdapter->addAdapter($textAdapter);
$multiAdapter->addAdapter($sqlAdapter);
$auth = new Auth($multiAdapter, $session);
$credentials = [
'username'=>'juser',
'password'=>'******'
];
// authenticate against the text adapter first, then the sql adapter.
$auth->login($credentials);
if ($auth->isValid()) {
//...
}
Other methods
If a user is valid, you can get the adapter for that user by userid.
<?php
$multiAdpater = $auth->getAdapter();
$userAdapter = $multiAdapter->getUserAdapter('juser');
// Now, you can access the public methods of the adapter for that user, if needed.