Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conduit/protocol/ConduitAPIRequest.php
12262 views
1
<?php
2
3
final 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 getValueExists($key) {
21
return array_key_exists($key, $this->params);
22
}
23
24
public function getAllParameters() {
25
return $this->params;
26
}
27
28
public function setUser(PhabricatorUser $user) {
29
$this->user = $user;
30
return $this;
31
}
32
33
/**
34
* Retrieve the authentic identity of the user making the request. If a
35
* method requires authentication (the default) the user object will always
36
* be available. If a method does not require authentication (i.e., overrides
37
* shouldRequireAuthentication() to return false) the user object will NEVER
38
* be available.
39
*
40
* @return PhabricatorUser Authentic user, available ONLY if the method
41
* requires authentication.
42
*/
43
public function getUser() {
44
if (!$this->user) {
45
throw new Exception(
46
pht(
47
'You can not access the user inside the implementation of a Conduit '.
48
'method which does not require authentication (as per %s).',
49
'shouldRequireAuthentication()'));
50
}
51
return $this->user;
52
}
53
54
public function getViewer() {
55
return $this->getUser();
56
}
57
58
public function setOAuthToken(
59
PhabricatorOAuthServerAccessToken $oauth_token) {
60
$this->oauthToken = $oauth_token;
61
return $this;
62
}
63
64
public function getOAuthToken() {
65
return $this->oauthToken;
66
}
67
68
public function setIsClusterRequest($is_cluster_request) {
69
$this->isClusterRequest = $is_cluster_request;
70
return $this;
71
}
72
73
public function getIsClusterRequest() {
74
return $this->isClusterRequest;
75
}
76
77
public function getIsStrictlyTyped() {
78
return $this->isStrictlyTyped;
79
}
80
81
public function newContentSource() {
82
return PhabricatorContentSource::newForSource(
83
PhabricatorConduitContentSource::SOURCECONST);
84
}
85
86
}
87
88