, singleton factory, singleton factory (Auth) login(), User, HTTP- .
. , factory, , , , db .
class auth {
private static $auth = null;
private $user = null;
private __construct(){};
public getAuth() {
if (is_null($this->auth) {
$this->auth = new auth();
}
return $this->auth;
}
public function login($user,$pass) {
...
if ($dbrow->user_type == 'admin') {
$this->user = new admin_user($dbrow);
} else {
$this->user = new normal_user($dbrow);
}
$this->user->setSession($db->getsession());
}
public function getUser() {
return $this->user;
}
public function saveSession() {
}
public function saveUser() {
}
...
}
, - , , .
class normal_user extends user {
... getters and setters
public function getName() {}
public function setEmail() {}
public function setprofile() {}
}
db, auth.
() - auth- > login().
$me = new normal_user();
$me->setName();
echo $me->getName();
, db, $auth- > user;
you can then create a function in auth to use custom objects to create new users (during registration)
...
public function create(user $user) {
$this->user = $user;
$this->saveUser();
}
...
you just need to make sure that you run the save functions at the end of execution ... maybe in the destructor ()
plain
source
share