blob: 8d3fbdf46daee960041144ec544c0df800ad5fea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<?php
namespace Mediawiki\Api;
use Exception;
/**
* A MultipartRequest is the same as a FluentRequest with additional support for setting request
* parameters (both normal parameters and headers) on multipart requests.
*
* @link http://docs.guzzlephp.org/en/stable/request-options.html#multipart
*
* @since 2.4.0
*/
class MultipartRequest extends FluentRequest {
/** @var mixed[] */
protected $multipartParams = [];
/**
* Check the structure of a multipart parameter array.
*
* @param mixed[] $params The multipart parameters to check.
*
* @throws Exception
*/
protected function checkMultipartParams( $params ) {
foreach ( $params as $key => $val ) {
if ( !is_array( $val ) ) {
throw new Exception( "Parameter '$key' must be an array." );
}
if ( !in_array( $key, array_keys( $this->getParams() ) ) ) {
throw new Exception( "Parameter '$key' is not already set on this request." );
}
}
}
/**
* Set all multipart parameters, replacing all existing ones.
*
* Each key of the array passed in here must be the name of a parameter already set on this
* request object.
*
* @param mixed[] $params The multipart parameters to use.
* @return $this
*/
public function setMultipartParams( $params ) {
$this->checkMultipartParams( $params );
$this->multipartParams = $params;
return $this;
}
/**
* Add extra multipart parameters.
*
* Each key of the array passed in here must be the name of a parameter already set on this
* request object.
*
* @param mixed[] $params The multipart parameters to add to any already present.
*
* @return $this
*/
public function addMultipartParams( $params ) {
$this->checkMultipartParams( $params );
$this->multipartParams = array_merge( $this->multipartParams, $params );
return $this;
}
/**
* Get all multipart request parameters.
*
* @return mixed[]
*/
public function getMultipartParams() {
return $this->multipartParams;
}
}
|