31 private $allModules = [];
33 private $generatedModules;
36 private $continuationData = [];
38 private $generatorContinuationData = [];
40 private $generatorNonContinuationData = [];
43 private $generatorParams = [];
45 private $generatorDone =
false;
54 ApiBase $module, array $allModules = [], array $generatedModules = []
56 $this->source = get_class( $module );
59 $this->generatedModules = $generatedModules
60 ? array_combine( $generatedModules, $generatedModules )
64 $continue = $request->getVal(
'continue',
'' );
65 if ( $continue !==
'' ) {
66 $continue = explode(
'||', $continue );
67 if ( count( $continue ) !== 2 ) {
70 $this->generatorDone = ( $continue[0] ===
'-' );
71 $skip = explode(
'|', $continue[1] );
72 if ( !$this->generatorDone ) {
73 $params = explode(
'|', $continue[0] );
74 $this->generatorParams = array_intersect_key(
75 $request->getValues(),
76 array_fill_keys( $params,
true )
81 $skip += $this->generatedModules;
85 foreach ( $allModules as $module ) {
87 if ( in_array( $name, $skip,
true ) ) {
88 $this->allModules[$name] =
false;
92 $this->allModules[$name] = $module;
102 return $this->source;
109 return $this->generatorDone;
117 return array_values( array_filter( $this->allModules ) );
129 if ( !isset( $this->allModules[$name] ) ) {
130 throw new UnexpectedValueException(
131 "Module '$name' called " . __METHOD__ .
132 ' but was not passed to ' . __CLASS__ .
'::__construct'
135 if ( !$this->allModules[$name] ) {
136 throw new UnexpectedValueException(
137 "Module '$name' was not supposed to have been executed, but " .
138 'it was executed anyway'
142 if ( is_array( $paramValue ) ) {
143 $paramValue = implode(
'|', $paramValue );
145 $this->continuationData[$name][$paramName] = $paramValue;
162 if ( is_array( $paramValue ) ) {
163 $paramValue = implode(
'|', $paramValue );
165 $this->generatorNonContinuationData[$name][$paramName] = $paramValue;
177 if ( is_array( $paramValue ) ) {
178 $paramValue = implode(
'|', $paramValue );
180 $this->generatorContinuationData[$name][$paramName] = $paramValue;
188 return array_merge_recursive( $this->continuationData, $this->generatorContinuationData );
197 return $this->generatorNonContinuationData;
206 $batchcomplete =
false;
208 $finishedModules = array_diff(
209 array_keys( $this->allModules ),
210 array_keys( $this->continuationData )
214 $continuationData = array_diff_key( $this->continuationData, $this->generatedModules );
215 foreach ( $continuationData as $kvp ) {
220 $continuationData = array_intersect_key( $this->continuationData, $this->generatedModules );
221 if ( $continuationData ) {
224 foreach ( $continuationData as $kvp ) {
227 $generatorParams = [];
228 foreach ( $this->generatorNonContinuationData as $kvp ) {
229 $generatorParams += $kvp;
231 $generatorParams += $this->generatorParams;
233 $data += $generatorParams;
234 $generatorKeys = implode(
'|', array_keys( $generatorParams ) );
235 } elseif ( $this->generatorContinuationData ) {
239 $generatorParams = [];
240 foreach ( $this->generatorContinuationData as $kvp ) {
241 $generatorParams += $kvp;
243 $data += $generatorParams;
244 $finishedModules = array_diff( $finishedModules, $this->generatedModules );
245 $generatorKeys = implode(
'|', array_keys( $generatorParams ) );
246 $batchcomplete =
true;
249 $generatorKeys =
'-';
250 $batchcomplete =
true;
255 if ( $data || $generatorKeys !==
'-' ) {
256 $data[
'continue'] = $generatorKeys .
'||' . implode(
'|', $finishedModules );
259 return [ $data, $batchcomplete ];
269 $result->
addValue(
null,
'continue', $data,
272 if ( $batchcomplete ) {
273 $result->
addValue(
null,
'batchcomplete',
true,
This abstract class implements many basic API functions, and is the base of all API classes.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
getMain()
Get the main module.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
This manages continuation state.
addGeneratorNonContinueParam(ApiBase $module, $paramName, $paramValue)
Set the non-continuation parameter for the generator module.
addGeneratorContinueParam(ApiBase $module, $paramName, $paramValue)
Set the continuation parameter for the generator module.
setContinuationIntoResult(ApiResult $result)
Store the continuation data into the result.
getRunModules()
Get the list of modules that should actually be run.
addContinueParam(ApiBase $module, $paramName, $paramValue)
Set the continuation parameter for a module.
getSource()
Get the class that created this manager.
getRawNonContinuation()
Fetch raw non-continuation data.
__construct(ApiBase $module, array $allModules=[], array $generatedModules=[])
getContinuation()
Fetch continuation result data.
getRawContinuation()
Fetch raw continuation data.
This class represents the result of the API operations.
addValue( $path, $name, $value, $flags=0)
Add value to the output data at the given path.
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
const ADD_ON_TOP
For addValue(), setValue() and similar functions, if the value does not exist, add it as the first el...
static newWithMessage(?ApiBase $module, $msg, $code=null, $data=null, $httpCode=0, Throwable $previous=null)