1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-10-22 03:16:04 +02:00
Files
php-auth/src/UserManager.php

43 lines
1.1 KiB
PHP

<?php
/*
* PHP-Auth (https://github.com/delight-im/PHP-Auth)
* Copyright (c) delight.im (https://www.delight.im/)
* Licensed under the MIT License (https://opensource.org/licenses/MIT)
*/
namespace Delight\Auth;
use Delight\Db\PdoDatabase;
use Delight\Db\PdoDsn;
require_once __DIR__ . '/Exceptions.php';
/** Abstract base class for components implementing user management */
abstract class UserManager {
/** @var PdoDatabase the database connection to operate on */
protected $db;
/**
* @param PdoDatabase|PdoDsn|\PDO $databaseConnection the database connection to operate on
*/
protected function __construct($databaseConnection) {
if ($databaseConnection instanceof PdoDatabase) {
$this->db = $databaseConnection;
}
elseif ($databaseConnection instanceof PdoDsn) {
$this->db = PdoDatabase::fromDsn($databaseConnection);
}
elseif ($databaseConnection instanceof \PDO) {
$this->db = PdoDatabase::fromPdo($databaseConnection, true);
}
else {
$this->db = null;
throw new \InvalidArgumentException('The database connection must be an instance of either `PdoDatabase`, `PdoDsn` or `PDO`');
}
}
}