33 private $apiMain =
null;
45 $this->apiMain = $apiMain;
52 if ( $this->apiMain ) {
53 return $this->apiMain;
57 $session = $context->getRequest()->getSession();
62 $fauxRequest =
new FauxRequest( [],
true, $session );
63 $fauxRequest->setSessionId( $session->getSessionId() );
66 $fauxContext->setRequest( $fauxRequest );
67 $fauxContext->setUser( $context->getUser() );
68 $fauxContext->setLanguage( $context->getLanguage() );
70 $this->apiMain =
new ApiMain( $fauxContext,
true );
71 return $this->apiMain;
82 $this->
getApiMain()->getModuleManager()->addModule(
86 'class' => get_class( $module ),
87 'factory' =>
static function () use ( $module ) {
109 foreach ( $params as $key => $value ) {
110 $request->setVal( $key, $value );
119 foreach ( $ex->
getStatusValue()->getErrorsByType(
'error' ) as $error ) {
127 'Unmapped action module error: ' . $ex->getMessage(),
132 $actionModuleResult = $apiMain->
getResult()->getResultData(
null, [
'Strip' =>
'all' ] );
187 array $actionModuleResult,
222 [
'actionModuleErrorCode' => $msg->
getApiCode() ]
238 $params[] = $this->makeMessageParam( $p );
249 private function makeMessageParam( $param ) {
250 if ( is_array( $param ) ) {
251 foreach ( $param as $type => $value ) {
252 if ( $type ===
'list' ) {
255 foreach ( $value as $v ) {
256 $paramList[] = $this->makeMessageParam( $v );
This abstract class implements many basic API functions, and is the base of all API classes.
This is the main API class, used for both external and internal processing.
getResult()
Get the ApiResult object associated with current request.
execute()
Execute api request.
Extension of Message implementing IApiMessage.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
Exception used to abort API execution with an error.
getStatusValue()
Fetch the error status.
Group all the pieces relevant to the context of a request into one instance.
static getMain()
Get the RequestContext object associated with the main request.
Interface for messages with machine-readable data for use by the API.
getApiCode()
Returns a machine-readable code for use by the API.
getParams()
Returns the message parameters.
getKey()
Returns the message key.