12use Wikimedia\ObjectFactory;
35 private const TYPE_DEFS = [
36 'boolean' => [
'class' => BooleanDef::class ],
37 'enum' => [
'class' => EnumDef::class ],
38 'integer' => [
'class' => IntegerDef::class ],
39 'float' => [
'class' => FloatDef::class ],
40 'double' => [
'class' => FloatDef::class ],
42 'class' => StringDef::class,
44 'allowEmptyWhenRequired' =>
true,
47 'password' => [
'class' => PasswordDef::class ],
48 'string' => [
'class' => StringDef::class ],
49 'timestamp' => [
'class' => TimestampDef::class ],
50 'upload' => [
'class' => UploadDef::class ],
51 'expiry' => [
'class' => ExpiryDef::class ],
53 'class' => TitleDef::class,
54 'services' => [
'TitleFactory' ],
57 'class' => UserDef::class,
58 'services' => [
'UserFactory',
'TitleFactory',
'UserNameUtils' ]
63 private const NO_BODY_METHODS = [
'GET',
'HEAD',
'DELETE' ];
66 private const BODY_METHODS = [
'POST',
'PUT' ];
69 private const FORM_DATA_CONTENT_TYPES = [
70 'application/x-www-form-urlencoded',
71 'multipart/form-data',
84 ObjectFactory $objectFactory,
92 'typeDefs' => self::TYPE_DEFS,
104 $validatedParams = [];
105 foreach ( $paramSettings as $name => $settings ) {
107 $validatedParams[$name] = $this->paramValidator->getValue( $name, $settings, [
112 'error' =>
'parameter-validation-failed',
120 return $validatedParams;
136 $method = strtoupper( trim( $request->
getMethod() ) );
139 if ( in_array( $method, self::NO_BODY_METHODS,
true ) ) {
144 list( $ct ) = explode(
';', $request->
getHeaderLine(
'Content-Type' ), 2 );
145 $ct = strtolower( trim( $ct ) );
149 if ( !in_array( $method, self::BODY_METHODS,
true ) ) {
151 $size = $body->getSize();
152 if ( $size ===
null ) {
154 if ( $body->isSeekable() ) {
157 $size = $body->read( 1 ) ===
'' ? 0 : 1;
163 throw new HttpException(
"A Content-Type header must be supplied with a request payload.", 415, [
164 'error' =>
'no-content-type',
170 if ( in_array( $ct, self::FORM_DATA_CONTENT_TYPES,
true ) ) {