Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.55% |
29 / 31 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApiFormatPhp | |
93.55% |
29 / 31 |
|
66.67% |
2 / 3 |
7.01 | |
0.00% |
0 / 1 |
getMimeType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
5.03 | |||
getAllowedParams | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com" |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | */ |
22 | |
23 | use Wikimedia\ParamValidator\ParamValidator; |
24 | |
25 | /** |
26 | * API Serialized PHP output formatter |
27 | * @ingroup API |
28 | */ |
29 | class ApiFormatPhp extends ApiFormatBase { |
30 | |
31 | public function getMimeType() { |
32 | return 'application/vnd.php.serialized'; |
33 | } |
34 | |
35 | public function execute() { |
36 | $params = $this->extractRequestParams(); |
37 | |
38 | switch ( $params['formatversion'] ) { |
39 | case 1: |
40 | $transforms = [ |
41 | 'BC' => [], |
42 | 'Types' => [], |
43 | 'Strip' => 'all', |
44 | ]; |
45 | break; |
46 | |
47 | case 2: |
48 | case 'latest': |
49 | $transforms = [ |
50 | 'Types' => [], |
51 | 'Strip' => 'all', |
52 | ]; |
53 | break; |
54 | |
55 | default: |
56 | // Should have been caught during parameter validation |
57 | self::dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' ); |
58 | } |
59 | $this->printText( serialize( $this->getResult()->getResultData( null, $transforms ) ) ); |
60 | } |
61 | |
62 | public function getAllowedParams() { |
63 | return parent::getAllowedParams() + [ |
64 | 'formatversion' => [ |
65 | ParamValidator::PARAM_TYPE => [ '1', '2', 'latest' ], |
66 | ParamValidator::PARAM_DEFAULT => '1', |
67 | ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion', |
68 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [ |
69 | '1' => 'apihelp-php-paramvalue-formatversion-1', |
70 | '2' => 'apihelp-php-paramvalue-formatversion-2', |
71 | 'latest' => 'apihelp-php-paramvalue-formatversion-latest', |
72 | ], |
73 | ], |
74 | ]; |
75 | } |
76 | } |