user.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php namespace Client\Request;
  2. class User extends Base {
  3. private $authenticated;
  4. public $uid;
  5. public $ulogin;
  6. public $ufull_name;
  7. public $uemail;
  8. public $uavatar_url;
  9. public $uusername;
  10. public function __construct(string $api_url, string $api_token, string $user = "") {
  11. $this->ulogin = (strlen($user) == 0 || $user == "me" ? "me" : $user);
  12. $this->authenticated = $this->ulogin == "me";
  13. parent::__construct($api_url, $api_token);
  14. }
  15. protected function set_scope(string $method) {
  16. switch($method) {
  17. default:
  18. $this->scope = ($this->ulogin == "me" ? "/user" : "/users/" . $this->ulogin);
  19. }
  20. }
  21. public function authenticated() {
  22. return $this->authenticated;
  23. }
  24. public function repos() {
  25. return new Repos($this->url, $this->token, $this);
  26. }
  27. public function repo(string $name) {
  28. return (new Repo($this->url, $this->token, $this, $name))->load();
  29. }
  30. protected function json_set_property($obj) {
  31. foreach ($obj as $key => $value) {
  32. $key = 'u' . $key;
  33. if (property_exists($this, $key))
  34. $this->{$key} = $value;
  35. }
  36. }
  37. }
  38. ?>