@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 93 lines 2.5 kB view raw
1<?php 2 3final class ConduitAPIRequest extends Phobject { 4 5 protected $params; 6 private $user; 7 private $isClusterRequest = false; 8 private $oauthToken; 9 private $isStrictlyTyped = true; 10 11 public function __construct(array $params, $strictly_typed) { 12 $this->params = $params; 13 $this->isStrictlyTyped = $strictly_typed; 14 } 15 16 public function getValue($key, $default = null) { 17 return coalesce(idx($this->params, $key), $default); 18 } 19 20 public function getIntValue($key, $default = 'undefined_magic_text') { 21 if ($default === 'undefined_magic_text' && !$this->getValueExists($key)) { 22 throw new Exception(pht('Required int param not provided: %s', $key)); 23 } 24 return (int)$this->getValue($key, $default); 25 } 26 27 public function getValueExists($key) { 28 return array_key_exists($key, $this->params); 29 } 30 31 public function getAllParameters() { 32 return $this->params; 33 } 34 35 public function setUser(PhabricatorUser $user) { 36 $this->user = $user; 37 return $this; 38 } 39 40 /** 41 * Retrieve the authentic identity of the user making the request. If a 42 * method requires authentication (the default) the user object will always 43 * be available. If a method does not require authentication (i.e., overrides 44 * shouldRequireAuthentication() to return false) the user object will NEVER 45 * be available. 46 * 47 * @return PhabricatorUser Authentic user, available ONLY if the method 48 * requires authentication. 49 */ 50 public function getUser() { 51 if (!$this->user) { 52 throw new Exception( 53 pht( 54 'You can not access the user inside the implementation of a Conduit '. 55 'method which does not require authentication (as per %s).', 56 'shouldRequireAuthentication()')); 57 } 58 return $this->user; 59 } 60 61 public function getViewer() { 62 return $this->getUser(); 63 } 64 65 public function setOAuthToken( 66 PhabricatorOAuthServerAccessToken $oauth_token) { 67 $this->oauthToken = $oauth_token; 68 return $this; 69 } 70 71 public function getOAuthToken() { 72 return $this->oauthToken; 73 } 74 75 public function setIsClusterRequest($is_cluster_request) { 76 $this->isClusterRequest = $is_cluster_request; 77 return $this; 78 } 79 80 public function getIsClusterRequest() { 81 return $this->isClusterRequest; 82 } 83 84 public function getIsStrictlyTyped() { 85 return $this->isStrictlyTyped; 86 } 87 88 public function newContentSource() { 89 return PhabricatorContentSource::newForSource( 90 PhabricatorConduitContentSource::SOURCECONST); 91 } 92 93}