| 1 | <?php |
||
| 16 | class StatementSetter { |
||
| 17 | |||
| 18 | private WikibaseApi $api; |
||
|
|
|||
| 19 | |||
| 20 | private \Serializers\Serializer $statementSerializer; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param WikibaseApi $api |
||
| 24 | * @param Serializer $statementSerializer |
||
| 25 | */ |
||
| 26 | public function __construct( WikibaseApi $api, Serializer $statementSerializer ) { |
||
| 27 | $this->api = $api; |
||
| 28 | $this->statementSerializer = $statementSerializer; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @since 0.5 |
||
| 33 | * |
||
| 34 | * @param Statement $statement |
||
| 35 | * @param EditInfo|null $editInfo |
||
| 36 | * |
||
| 37 | * @throws InvalidArgumentException |
||
| 38 | * |
||
| 39 | * @todo allow setting of indexes |
||
| 40 | */ |
||
| 41 | public function set( Statement $statement, EditInfo $editInfo = null ): bool { |
||
| 42 | if ( $statement->getGuid() === null ) { |
||
| 43 | throw new InvalidArgumentException( 'Can not set a statement that does not have a GUID' ); |
||
| 44 | } |
||
| 45 | |||
| 46 | $params = [ |
||
| 47 | 'claim' => json_encode( $this->statementSerializer->serialize( $statement ) ), |
||
| 48 | ]; |
||
| 49 | |||
| 50 | $this->api->postRequest( 'wbsetclaim', $params, $editInfo ); |
||
| 51 | return true; |
||
| 52 | } |
||
| 53 | |||
| 54 | } |
||
| 55 |