| 1 |
<?php |
| 2 |
|
| 3 |
namespace League\OAuth2\Client\Provider; |
| 4 |
|
| 5 |
use League\OAuth2\Client\Tool\ArrayAccessorTrait; |
| 6 |
|
| 7 |
class GithubResourceOwner implements ResourceOwnerInterface |
| 8 |
{ |
| 9 |
use ArrayAccessorTrait; |
| 10 |
|
| 11 |
/** |
| 12 |
* Domain |
| 13 |
* |
| 14 |
* @var string |
| 15 |
*/ |
| 16 |
protected $domain; |
| 17 |
|
| 18 |
/** |
| 19 |
* Raw response |
| 20 |
* |
| 21 |
* @var array |
| 22 |
*/ |
| 23 |
protected $response; |
| 24 |
|
| 25 |
/** |
| 26 |
* Creates new resource owner. |
| 27 |
* |
| 28 |
* @param array $response |
| 29 |
*/ |
| 30 |
public function __construct(array $response = array()) |
| 31 |
{ |
| 32 |
$this->response = $response; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get resource owner id |
| 37 |
* |
| 38 |
* @return int|null |
| 39 |
*/ |
| 40 |
public function getId() |
| 41 |
{ |
| 42 |
return $this->getValueByKey($this->response, 'id'); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get resource owner email |
| 47 |
* |
| 48 |
* @return string|null |
| 49 |
*/ |
| 50 |
public function getEmail() |
| 51 |
{ |
| 52 |
return $this->getValueByKey($this->response, 'email'); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Get resource owner name |
| 57 |
* |
| 58 |
* @return string|null |
| 59 |
*/ |
| 60 |
public function getName() |
| 61 |
{ |
| 62 |
return $this->getValueByKey($this->response, 'name'); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Get resource owner nickname |
| 67 |
* |
| 68 |
* @return string|null |
| 69 |
*/ |
| 70 |
public function getNickname() |
| 71 |
{ |
| 72 |
return $this->getValueByKey($this->response, 'login'); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Get resource owner url |
| 77 |
* |
| 78 |
* @return string|null |
| 79 |
*/ |
| 80 |
public function getUrl() |
| 81 |
{ |
| 82 |
$urlParts = array_filter([$this->domain, $this->getNickname()]); |
| 83 |
|
| 84 |
return count($urlParts) ? implode('/', $urlParts) : null; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Set resource owner domain |
| 89 |
* |
| 90 |
* @param string $domain |
| 91 |
* |
| 92 |
* @return ResourceOwner |
| 93 |
*/ |
| 94 |
public function setDomain($domain) |
| 95 |
{ |
| 96 |
$this->domain = $domain; |
| 97 |
|
| 98 |
return $this; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Return all of the owner details available as an array. |
| 103 |
* |
| 104 |
* @return array |
| 105 |
*/ |
| 106 |
public function toArray() |
| 107 |
{ |
| 108 |
return $this->response; |
| 109 |
} |
| 110 |
} |
| 111 |
|