in a CMR project which manages Radius authentications (create user, renew user, delete user, expire time, etc)
I want to create user in multiple accounting servers such as free radius , mikrotik user manager radius etc ... I already developed the API for those accounting servers the thing I can't figure our is that how I should call a method to trigger ie a method called create_user() in all modules (free radius.inc.php , userman.inc.php ) to create a user in all accounting servers.
lets say create_user() method exists on all of them .
I also want to add more accounting server classes to the project later , i don't want to hard code for another accounting support implementation
thanks in advance
I'm not sure if if i understand what you mean but let's give it a try. To abstract your accounting servers
you should use an interface.
<?php
interface AccountingServer {
public function create_user();
}
class Server1 implements AccountingServer {
public function create_user()
{
echo "Create user on server 1";
}
}
class Server2 implements AccountingServer {
public function create_user()
{
echo "Create user on server 2";
}
}
$server1 = new Server1();
$server1->create_user();
$server2 = new Server2();
$server2->create_user();
?>
If you mean to share the create_user()
method in all your accounting servers
you should use parent-child structure.
<?php
abstract class AccountingServer {
public function create_user()
{
echo "Create user";
}
}
class Server1 extends AccountingServer {
}
class Server2 extends AccountingServer {
}
$server1 = new Server1();
$server1->create_user();
$server2 = new Server2();
$server2->create_user();
?>
Does this answer your question?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.