Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.43% |
27 / 28 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ApiFormatPhp | |
100.00% |
27 / 27 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| getMimeType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| getAllowedParams | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com" |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | use Wikimedia\ParamValidator\ParamValidator; |
| 12 | |
| 13 | /** |
| 14 | * API Serialized PHP output formatter |
| 15 | * @ingroup API |
| 16 | */ |
| 17 | class ApiFormatPhp extends ApiFormatBase { |
| 18 | |
| 19 | /** @inheritDoc */ |
| 20 | public function getMimeType() { |
| 21 | return 'application/vnd.php.serialized'; |
| 22 | } |
| 23 | |
| 24 | public function execute() { |
| 25 | $params = $this->extractRequestParams(); |
| 26 | $transforms = match ( $params['formatversion'] ) { |
| 27 | '1' => [ |
| 28 | 'BC' => [], |
| 29 | 'Types' => [], |
| 30 | 'Strip' => 'all', |
| 31 | ], |
| 32 | '2', 'latest' => [ |
| 33 | 'Types' => [], |
| 34 | 'Strip' => 'all', |
| 35 | ], |
| 36 | // Should have been caught during parameter validation |
| 37 | // @phan-suppress-next-line PhanUseReturnValueOfNever |
| 38 | default => self::dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' ) |
| 39 | }; |
| 40 | $this->printText( serialize( $this->getResult()->getResultData( null, $transforms ) ) ); |
| 41 | } |
| 42 | |
| 43 | /** @inheritDoc */ |
| 44 | public function getAllowedParams() { |
| 45 | return parent::getAllowedParams() + [ |
| 46 | 'formatversion' => [ |
| 47 | ParamValidator::PARAM_TYPE => [ '1', '2', 'latest' ], |
| 48 | ParamValidator::PARAM_DEFAULT => '1', |
| 49 | ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion', |
| 50 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [ |
| 51 | '1' => 'apihelp-php-paramvalue-formatversion-1', |
| 52 | '2' => 'apihelp-php-paramvalue-formatversion-2', |
| 53 | 'latest' => 'apihelp-php-paramvalue-formatversion-latest', |
| 54 | ], |
| 55 | ], |
| 56 | ]; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** @deprecated class alias since 1.43 */ |
| 61 | class_alias( ApiFormatPhp::class, 'ApiFormatPhp' ); |