11use Wikimedia\ObjectFactory;
34 private const TYPE_DEFS = [
35 'boolean' => [
'class' => BooleanDef::class ],
36 'enum' => [
'class' => EnumDef::class ],
37 'integer' => [
'class' => IntegerDef::class ],
38 'float' => [
'class' => FloatDef::class ],
39 'double' => [
'class' => FloatDef::class ],
41 'class' => StringDef::class,
43 'allowEmptyWhenRequired' =>
true,
46 'password' => [
'class' => PasswordDef::class ],
47 'string' => [
'class' => StringDef::class ],
48 'timestamp' => [
'class' => TimestampDef::class ],
49 'upload' => [
'class' => UploadDef::class ],
50 'expiry' => [
'class' => ExpiryDef::class ],
54 private const NO_BODY_METHODS = [
'GET',
'HEAD',
'DELETE' ];
57 private const BODY_METHODS = [
'POST',
'PUT' ];
60 private const FORM_DATA_CONTENT_TYPES = [
61 'application/x-www-form-urlencoded',
62 'multipart/form-data',
76 ObjectFactory $objectFactory,
85 'typeDefs' => self::TYPE_DEFS,
97 $validatedParams = [];
98 foreach ( $paramSettings as $name => $settings ) {
100 $validatedParams[$name] = $this->paramValidator->getValue( $name, $settings, [
105 'error' =>
'parameter-validation-failed',
113 return $validatedParams;
129 $method = strtoupper( trim( $request->
getMethod() ) );
132 if ( in_array( $method, self::NO_BODY_METHODS,
true ) ) {
137 list( $ct ) = explode(
';', $request->
getHeaderLine(
'Content-Type' ), 2 );
138 $ct = strtolower( trim( $ct ) );
142 if ( !in_array( $method, self::BODY_METHODS,
true ) ) {
144 $size = $body->getSize();
145 if ( $size ===
null ) {
147 if ( $body->isSeekable() ) {
150 $size = $body->read( 1 ) ===
'' ? 0 : 1;
156 throw new HttpException(
"A Content-Type header must be supplied with a request payload.", 415, [
157 'error' =>
'no-content-type',
163 if ( in_array( $ct, self::FORM_DATA_CONTENT_TYPES,
true ) ) {