Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2894094
ConduitCall.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
2 KB
Referenced Files
None
Subscribers
None
ConduitCall.php
View Options
<?php
/**
* Run a conduit method in-process, without requiring HTTP requests. Usage:
*
* $call = new ConduitCall('method.name', array('param' => 'value'));
* $call->setUser($user);
* $result = $call->execute();
*
*/
final
class
ConduitCall
{
private
$method
;
private
$params
;
private
$request
;
private
$user
;
public
function
__construct
(
$method
,
array
$params
)
{
$this
->
method
=
$method
;
$this
->
params
=
$params
;
$this
->
handler
=
$this
->
buildMethodHandler
(
$method
)
;
$this
->
request
=
new
ConduitAPIRequest
(
$params
)
;
}
public
function
setUser
(
PhabricatorUser
$user
)
{
$this
->
user
=
$user
;
return
$this
;
}
public
function
getUser
(
)
{
return
$this
->
user
;
}
public
function
shouldRequireAuthentication
(
)
{
return
$this
->
handler
->
shouldRequireAuthentication
(
)
;
}
public
function
shouldAllowUnguardedWrites
(
)
{
return
$this
->
handler
->
shouldAllowUnguardedWrites
(
)
;
}
public
function
getRequiredScope
(
)
{
return
$this
->
handler
->
getRequiredScope
(
)
;
}
public
function
getErrorDescription
(
$code
)
{
return
$this
->
handler
->
getErrorDescription
(
$code
)
;
}
public
function
execute
(
)
{
if
(
!
$this
->
getUser
(
)
)
{
if
(
$this
->
shouldRequireAuthentication
(
)
)
{
throw
new
ConduitException
(
"ERR-INVALID-AUTH"
)
;
}
}
else
{
$this
->
request
->
setUser
(
$this
->
getUser
(
)
)
;
}
return
$this
->
handler
->
executeMethod
(
$this
->
request
)
;
}
protected
function
buildMethodHandler
(
$method
)
{
$method_class
=
ConduitAPIMethod
::
getClassNameFromAPIMethodName
(
$method
)
;
// Test if the method exists.
$ok
=
false
;
try
{
$ok
=
class_exists
(
$method_class
)
;
}
catch
(
Exception
$ex
)
{
// Discard, we provide a more specific exception below.
}
if
(
!
$ok
)
{
throw
new
Exception
(
"Conduit method '{$method}' does not exist."
)
;
}
$class_info
=
new
ReflectionClass
(
$method_class
)
;
if
(
$class_info
->
isAbstract
(
)
)
{
throw
new
Exception
(
"Method '{$method}' is not valid; the implementation is an abstract "
.
"base class."
)
;
}
$method
=
newv
(
$method_class
,
array
(
)
)
;
if
(
!
(
$method
instanceof
ConduitAPIMethod
)
)
{
throw
new
ConduitException
(
"Method '{$method}' is not valid; the implementation must be "
.
"a subclass of ConduitAPIMethod."
)
;
}
return
$method
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 19:22 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1127927
Default Alt Text
ConduitCall.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment