Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| UnsupportedContentTypeBodyValidator | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| validateBody | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Rest\Validator; |
| 4 | |
| 5 | use MediaWiki\Rest\LocalizedHttpException; |
| 6 | use MediaWiki\Rest\RequestInterface; |
| 7 | use Wikimedia\Message\MessageValue; |
| 8 | |
| 9 | /** |
| 10 | * Validator that always fails. Meant as a convenience for Handler::getBodyValidator(): |
| 11 | * |
| 12 | * public function getBodyValidator( $contentType ) { |
| 13 | * if ( $contentType === 'supported/content-type' ) { |
| 14 | * return new MyValidator(); |
| 15 | * } |
| 16 | * return new UnsupportedContentTypeBodyValidator( $contentType ); |
| 17 | * } |
| 18 | * |
| 19 | * @since 1.40 |
| 20 | */ |
| 21 | class UnsupportedContentTypeBodyValidator implements BodyValidator { |
| 22 | |
| 23 | private string $contentType; |
| 24 | |
| 25 | public function __construct( string $contentType ) { |
| 26 | $this->contentType = $contentType; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | * @return never |
| 32 | */ |
| 33 | public function validateBody( RequestInterface $request ): never { |
| 34 | throw new LocalizedHttpException( |
| 35 | new MessageValue( 'rest-unsupported-content-type', [ $this->contentType ] ), |
| 36 | 415 |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | } |