12use Wikimedia\ObjectFactory\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' => [
'UserIdentityLookup',
'TitleParser',
'UserNameUtils' ]
63 private const NO_BODY_METHODS = [
'GET',
'HEAD' ];
66 private const BODY_METHODS = [
'POST',
'PUT' ];
73 private const FORM_DATA_CONTENT_TYPES = [
74 'application/x-www-form-urlencoded',
75 'multipart/form-data',
79 private $paramValidator;
88 ObjectFactory $objectFactory,
96 'typeDefs' => self::TYPE_DEFS,
108 $validatedParams = [];
109 foreach ( $paramSettings as $name => $settings ) {
111 $validatedParams[$name] = $this->paramValidator->getValue( $name, $settings, [
116 'error' =>
'parameter-validation-failed',
124 return $validatedParams;
140 $method = strtoupper( trim( $request->
getMethod() ) );
143 if ( in_array( $method, self::NO_BODY_METHODS,
true ) ) {
148 [ $ct ] = explode(
';', $request->
getHeaderLine(
'Content-Type' ), 2 );
149 $ct = strtolower( trim( $ct ) );
153 if ( !in_array( $method, self::BODY_METHODS,
true ) ) {
155 $size = $body->getSize();
156 if ( $size ===
null ) {
158 if ( $body->isSeekable() ) {
161 $size = $body->read( 1 ) ===
'' ? 0 : 1;
167 throw new HttpException(
"A Content-Type header must be supplied with a request payload.", 415, [
168 'error' =>
'no-content-type',
174 if ( in_array( $ct, self::FORM_DATA_CONTENT_TYPES,
true ) ) {