Changeset View
Changeset View
Standalone View
Standalone View
src/ref/user/ArcanistUserRef.php
| <?php | <?php | ||||
| final class ArcanistUserRef | final class ArcanistUserRef | ||||
| extends ArcanistRef { | extends ArcanistRef | ||||
| implements | |||||
| ArcanistDisplayRefInterface { | |||||
| private $parameters; | private $parameters; | ||||
| public function getRefDisplayName() { | public function getRefDisplayName() { | ||||
| return pht('User "%s"', $this->getUsername()); | return pht('User "%s"', $this->getUsername()); | ||||
| } | } | ||||
| public static function newFromConduit(array $parameters) { | public static function newFromConduit(array $parameters) { | ||||
| $ref = new self(); | $ref = new self(); | ||||
| $ref->parameters = $parameters; | $ref->parameters = $parameters; | ||||
| return $ref; | return $ref; | ||||
| } | } | ||||
| public static function newFromConduitWhoami(array $parameters) { | public static function newFromConduitWhoami(array $parameters) { | ||||
| // NOTE: The "user.whoami" call returns a different structure than | // NOTE: The "user.whoami" call returns a different structure than | ||||
| // "user.search". Mangle the data so it looks similar. | // "user.search". Mangle the data so it looks similar. | ||||
| $parameters['fields'] = array( | $parameters['fields'] = array( | ||||
| 'username' => idx($parameters, 'userName'), | 'username' => idx($parameters, 'userName'), | ||||
| 'realName' => idx($parameters, 'realName'), | |||||
| ); | ); | ||||
| return self::newFromConduit($parameters); | return self::newFromConduit($parameters); | ||||
| } | } | ||||
| public function getUsername() { | public function getUsername() { | ||||
| return idxv($this->parameters, array('fields', 'username')); | return idxv($this->parameters, array('fields', 'username')); | ||||
| } | } | ||||
| public function getRealName() { | |||||
| var_dump($this->parameters); | |||||
| return idxv($this->parameters, array('fields', 'realName')); | |||||
| } | |||||
| public function getDisplayRefObjectName() { | |||||
| return '@'.$this->getUsername(); | |||||
| } | |||||
| public function getDisplayRefTitle() { | |||||
| $real_name = $this->getRealName(); | |||||
| if (strlen($real_name)) { | |||||
| $real_name = sprintf('(%s)', $real_name); | |||||
| } | |||||
| return $real_name; | |||||
| } | |||||
| } | } | ||||