/** * @param PageIdentifier $pageIdentifier * * @return PromiseInterface of array the parse result (raw from the api) */ public function parsePageAsync(PageIdentifier $pageIdentifier) { $params = []; if ($pageIdentifier->getId() !== null) { $params['pageid'] = $pageIdentifier->getId(); } elseif ($pageIdentifier->getTitle() !== null) { $params['page'] = $pageIdentifier->getTitle()->getText(); } else { throw new \RuntimeException('No way to identify page'); } $promise = $this->api->getRequestAsync(new SimpleRequest('parse', $params)); return $promise->then(function ($result) { return $result['parse']; }); }
/** * @since 0.7 * * @param string|string[] $inputValues one or more * @param string $parser Id of the ValueParser to use * * @returns Promise of a DataValue object or array of DataValue objects with same keys as values */ public function parseAsync($inputValues, $parser) { $promise = $this->api->getRequestAsync(new SimpleRequest('wbparsevalue', array('parser' => $parser, 'values' => implode('|', $inputValues)))); return $promise->then(function ($result) use($inputValues) { if (is_array($inputValues)) { $indexedResults = array(); foreach ($result['results'] as $resultElement) { if (in_array($resultElement['raw'], $inputValues)) { $indexedResults[array_search($resultElement['raw'], $inputValues)] = $this->dataValueDeserializer->deserialize($resultElement); } else { throw new RuntimeException("Failed to match parse results with input data"); } } return $indexedResults; } else { return $this->dataValueDeserializer->deserialize($result['results'][0]); } }); }