Skip to content

Account Management

Đorđe Jocić edited this page Jan 2, 2019 · 1 revision

Account Manager class can be used for, you guessed it, managing accounts on local file system. To add an account simply use the following snippet.

Adding

$accountManager = new Jocic\GoogleAuthenticator\AccountManager();

$accountManager->addAccount($account);

Newly added account will receive an ID used for easier referencing. Also, you should keep in mind that:

  • Account ID is only unique in relation to it's manager
  • Account can only be added to one account manager
  • Account, belonging to a a manager, will hold it's reference

For getting an assigned ID, use the snippet below. Returned value will be "NULL" if account wasn't assigned.

$accountId = $account->getAccountId();

To get manager's reference use the following snippet. As with the ID method, returned value will be "NULL" if account wasn't assigned to a manager.

$accountManager = $account->getAccountManager();

Removing

Account removal is extremely easy and can be achieved by utilizing the "remove" method and passing an ID value.

$accountManager->removeAccount(12); // By ID
$accountManager->removeAccount("[email protected]"); // By Name
$accountManager->removeAccount($account); // By Object

Keep in mind that uniqueness of an account name isn't enforced.

Finding

Finding stored accounts is done in the same fashion.

$account = $accountManager->findAccount(12); // By ID
$account = $accountManager->findAccount("[email protected]"); // By Name
$account = $accountManager->findAccount($account); // By Object

Saving

Saving accounts is done by calling the "save" method.

if (!$accountManager->save("my-writable-file.dat"))
{
    // Handle IO Error
}

Loading

Loading accounts is just as easy as saving them, it's done by calling the "load" method.

if (!$accountManager->load("my-readable-file.dat"))
{
    // Handle IO Error
}
Clone this wiki locally