| 1 | <?php |
||
| 15 | class Parser extends Service { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param PageIdentifier $pageIdentifier |
||
| 19 | * |
||
| 20 | * @return array the parse result (raw from the api) |
||
| 21 | */ |
||
| 22 | public function parsePage( PageIdentifier $pageIdentifier ): array { |
||
| 23 | return $this->parsePageAsync( $pageIdentifier )->wait(); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param PageIdentifier $pageIdentifier |
||
| 28 | * |
||
| 29 | * @return PromiseInterface of array the parse result (raw from the api) |
||
| 30 | */ |
||
| 31 | public function parsePageAsync( PageIdentifier $pageIdentifier ): \GuzzleHttp\Promise\PromiseInterface { |
||
| 32 | $params = []; |
||
| 33 | if ( $pageIdentifier->getId() !== null ) { |
||
| 34 | $params['pageid'] = $pageIdentifier->getId(); |
||
| 35 | } elseif ( $pageIdentifier->getTitle() !== null ) { |
||
| 36 | $params['page'] = $pageIdentifier->getTitle()->getText(); |
||
| 37 | } else { |
||
| 38 | throw new RuntimeException( 'No way to identify page' ); |
||
| 39 | } |
||
| 40 | |||
| 41 | $promise = $this->api->getRequestAsync( new SimpleRequest( 'parse', $params ) ); |
||
| 42 | |||
| 43 | return $promise->then( fn( $result ) => $result['parse'] ); |
||
|
|
|||
| 44 | } |
||
| 45 | |||
| 46 | } |
||
| 47 |