Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Vendor\App;
- class User
- {
- private $bug;
- private $email;
- private $password;
- private $fillable = ['email'];
- private $accessible = ['email'];
- private $isAdmin = false;
- public function __construct(array $params = [])
- {
- if (count($params)) {
- foreach ($params as $key => $value) {
- $this->$key = $value;
- }
- }
- }
- public function __set($name, $value)
- {
- if (!in_array($name, $this->fillable)) return false;
- if (isset($this->$name))
- {
- $this->$name = $value;
- }
- }
- public function __get($name)
- {
- if (!in_array($name, $this->accessible)) return null;
- return $this->$name ?? null;
- }
- public function __toString()
- {
- $data = [];
- foreach ($this->accessible as $key) {
- $data[$key] = $this->$key;
- }
- return json_encode($data);
- }
- public function login()
- {
- return 'logging in as ' . $this->email . ' ...';
- }
- public function logout()
- {
- return "$this->email has logged out...";
- }
- public function setPassword($string)
- {
- $this->password = $string;
- return $this;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function setEmail($string)
- {
- $this->email = $string;
- return $this;
- }
- public function getEmail()
- {
- return $this->email;
- }
- }
Add Comment
Please, Sign In to add comment