class ApiContinuationManager {
private $source;
- private $allModules = array();
- private $generatedModules = array();
+ private $allModules = [];
+ private $generatedModules = [];
- private $continuationData = array();
- private $generatorContinuationData = array();
+ private $continuationData = [];
+ private $generatorContinuationData = [];
+ private $generatorNonContinuationData = [];
- private $generatorParams = array();
+ private $generatorParams = [];
private $generatorDone = false;
/**
* @throws UsageException
*/
public function __construct(
- ApiBase $module, array $allModules = array(), array $generatedModules = array()
+ ApiBase $module, array $allModules = [], array $generatedModules = []
) {
$this->source = get_class( $module );
$request = $module->getRequest();
$this->generatedModules = $generatedModules
? array_combine( $generatedModules, $generatedModules )
- : array();
+ : [];
- $skip = array();
+ $skip = [];
$continue = $request->getVal( 'continue', '' );
if ( $continue !== '' ) {
$continue = explode( '||', $continue );
}
$paramName = $module->encodeParamName( $paramName );
if ( is_array( $paramValue ) ) {
- $paramValue = join( '|', $paramValue );
+ $paramValue = implode( '|', $paramValue );
}
$this->continuationData[$name][$paramName] = $paramValue;
}
+ /**
+ * Set the non-continuation parameter for the generator module
+ *
+ * In case the generator isn't going to be continued, this sets the fields
+ * to return.
+ *
+ * @since 1.28
+ * @param ApiBase $module
+ * @param string $paramName
+ * @param string|array $paramValue
+ */
+ public function addGeneratorNonContinueParam( ApiBase $module, $paramName, $paramValue ) {
+ $name = $module->getModuleName();
+ $paramName = $module->encodeParamName( $paramName );
+ if ( is_array( $paramValue ) ) {
+ $paramValue = implode( '|', $paramValue );
+ }
+ $this->generatorNonContinuationData[$name][$paramName] = $paramValue;
+ }
+
/**
* Set the continuation parameter for the generator module
* @param ApiBase $module
$name = $module->getModuleName();
$paramName = $module->encodeParamName( $paramName );
if ( is_array( $paramValue ) ) {
- $paramValue = join( '|', $paramValue );
+ $paramValue = implode( '|', $paramValue );
}
$this->generatorContinuationData[$name][$paramName] = $paramValue;
}
return array_merge_recursive( $this->continuationData, $this->generatorContinuationData );
}
+ /**
+ * Fetch raw non-continuation data
+ * @since 1.28
+ * @return array
+ */
+ public function getRawNonContinuation() {
+ return $this->generatorNonContinuationData;
+ }
+
/**
* Fetch continuation result data
- * @return array Array( (array)$data, (bool)$batchcomplete )
+ * @return array [ (array)$data, (bool)$batchcomplete ]
*/
public function getContinuation() {
- $data = array();
+ $data = [];
$batchcomplete = false;
$finishedModules = array_diff(
foreach ( $continuationData as $module => $kvp ) {
$data += $kvp;
}
- $data += $this->generatorParams;
- $generatorKeys = join( '|', array_keys( $this->generatorParams ) );
+ $generatorParams = [];
+ foreach ( $this->generatorNonContinuationData as $kvp ) {
+ $generatorParams += $kvp;
+ }
+ $generatorParams += $this->generatorParams;
+ $data += $generatorParams;
+ $generatorKeys = implode( '|', array_keys( $generatorParams ) );
} elseif ( $this->generatorContinuationData ) {
// All the generator-using modules are complete, but the
// generator isn't. Continue the generator and restart the
// generator-using modules
- $generatorParams = array();
+ $generatorParams = [];
foreach ( $this->generatorContinuationData as $kvp ) {
$generatorParams += $kvp;
}
$data += $generatorParams;
$finishedModules = array_diff( $finishedModules, $this->generatedModules );
- $generatorKeys = join( '|', array_keys( $generatorParams ) );
+ $generatorKeys = implode( '|', array_keys( $generatorParams ) );
$batchcomplete = true;
} else {
// Generator and prop modules are all done. Mark it so.
// Set 'continue' if any continuation data is set or if the generator
// still needs to run
if ( $data || $generatorKeys !== '-' ) {
- $data['continue'] = $generatorKeys . '||' . join( '|', $finishedModules );
+ $data['continue'] = $generatorKeys . '||' . implode( '|', $finishedModules );
}
- return array( $data, $batchcomplete );
+ return [ $data, $batchcomplete ];
}
/**