2011-01-24 09:00:29 -08:00
|
|
|
<?php
|
|
|
|
|
2015-06-15 18:02:26 +10:00
|
|
|
final class ConduitAPIRequest extends Phobject {
|
2011-01-24 09:00:29 -08:00
|
|
|
|
|
|
|
protected $params;
|
2011-04-07 18:27:39 -07:00
|
|
|
private $user;
|
2015-01-23 13:30:52 -08:00
|
|
|
private $isClusterRequest = false;
|
2011-01-24 09:00:29 -08:00
|
|
|
|
|
|
|
public function __construct(array $params) {
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2012-03-06 15:12:27 -08:00
|
|
|
public function getValue($key, $default = null) {
|
|
|
|
return coalesce(idx($this->params, $key), $default);
|
2011-01-24 09:00:29 -08:00
|
|
|
}
|
|
|
|
|
2015-12-13 03:53:15 -08:00
|
|
|
public function getValueExists($key) {
|
|
|
|
return array_key_exists($key, $this->params);
|
|
|
|
}
|
|
|
|
|
2011-01-24 09:00:29 -08:00
|
|
|
public function getAllParameters() {
|
|
|
|
return $this->params;
|
|
|
|
}
|
|
|
|
|
2012-01-10 16:48:59 -08:00
|
|
|
public function setUser(PhabricatorUser $user) {
|
2011-04-07 18:27:39 -07:00
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the authentic identity of the user making the request. If a
|
|
|
|
* method requires authentication (the default) the user object will always
|
|
|
|
* be available. If a method does not require authentication (i.e., overrides
|
|
|
|
* shouldRequireAuthentication() to return false) the user object will NEVER
|
|
|
|
* be available.
|
|
|
|
*
|
|
|
|
* @return PhabricatorUser Authentic user, available ONLY if the method
|
|
|
|
* requires authentication.
|
|
|
|
*/
|
|
|
|
public function getUser() {
|
|
|
|
if (!$this->user) {
|
|
|
|
throw new Exception(
|
2015-05-22 17:27:56 +10:00
|
|
|
pht(
|
|
|
|
'You can not access the user inside the implementation of a Conduit '.
|
|
|
|
'method which does not require authentication (as per %s).',
|
|
|
|
'shouldRequireAuthentication()'));
|
2011-04-07 18:27:39 -07:00
|
|
|
}
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2015-01-23 13:30:52 -08:00
|
|
|
public function setIsClusterRequest($is_cluster_request) {
|
|
|
|
$this->isClusterRequest = $is_cluster_request;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIsClusterRequest() {
|
|
|
|
return $this->isClusterRequest;
|
|
|
|
}
|
|
|
|
|
2016-03-25 05:56:16 -07:00
|
|
|
public function newContentSource() {
|
|
|
|
return PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorConduitContentSource::SOURCECONST);
|
|
|
|
}
|
|
|
|
|
2011-01-24 09:00:29 -08:00
|
|
|
}
|