Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
GenerateUcfirstOverrides | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
loadJson | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * Generate a php file containing an array of |
4 | * utf8_lowercase => utf8_uppercase |
5 | * overrides. Takes as input two json files generated with generateUpperCharTable.php |
6 | * as input. |
7 | * |
8 | * Example: Prepare Language::ucfirst on newer PHP 7.4 to work like the current PHP 7.2 |
9 | * |
10 | * $ php7.2 maintenance/language/generateUpperCharTable.php --outfile php72.json |
11 | * $ php7.4 maintenance/language/generateUpperCharTable.php --outfile php74.json |
12 | * $ php7.2 maintenance/language/generateUcfirstOverrides.php \ |
13 | * --override php74.json --with php72.json --outfile test.php |
14 | * |
15 | * This program is free software; you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation; either version 2 of the License, or |
18 | * (at your option) any later version. |
19 | * |
20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. |
24 | * |
25 | * You should have received a copy of the GNU General Public License along |
26 | * with this program; if not, write to the Free Software Foundation, Inc., |
27 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
28 | * http://www.gnu.org/copyleft/gpl.html |
29 | * |
30 | * @file |
31 | * @ingroup MaintenanceLanguage |
32 | */ |
33 | |
34 | use Wikimedia\StaticArrayWriter; |
35 | |
36 | // @codeCoverageIgnoreStart |
37 | require_once __DIR__ . '/../Maintenance.php'; |
38 | // @codeCoverageIgnoreEnd |
39 | |
40 | class GenerateUcfirstOverrides extends Maintenance { |
41 | |
42 | public function __construct() { |
43 | parent::__construct(); |
44 | $this->addDescription( |
45 | 'Generates a php source file containing a definition for mb_strtoupper overrides' ); |
46 | $this->addOption( 'outfile', 'Output file', true, true, 'o' ); |
47 | $this->addOption( 'override', 'Char table we want to avoid (e.g. future PHP)', |
48 | true, true, false, true ); |
49 | $this->addOption( 'with', 'Char table we want to obtain or preserve (e.g. current PHP)', true, true ); |
50 | } |
51 | |
52 | public function execute() { |
53 | $outfile = $this->getOption( 'outfile' ); |
54 | $fromTables = []; |
55 | foreach ( $this->getOption( 'override' ) as $fileName ) { |
56 | $fromTables[] = $this->loadJson( $fileName ); |
57 | } |
58 | $to = $this->loadJson( $this->getOption( 'with' ) ); |
59 | $overrides = []; |
60 | |
61 | foreach ( $fromTables as $from ) { |
62 | foreach ( $from as $lc => $uc ) { |
63 | $ref = $to[$lc] ?? null; |
64 | if ( $ref !== null && $ref !== $uc ) { |
65 | $overrides[$lc] = $ref; |
66 | } |
67 | } |
68 | } |
69 | ksort( $overrides ); |
70 | $writer = new StaticArrayWriter(); |
71 | file_put_contents( |
72 | $outfile, |
73 | $writer->create( $overrides, 'File created by generateUcfirstOverrides.php' ) |
74 | ); |
75 | } |
76 | |
77 | private function loadJson( $filename ) { |
78 | $data = file_get_contents( $filename ); |
79 | if ( $data === false ) { |
80 | $msg = sprintf( "Could not load data from file '%s'\n", $filename ); |
81 | $this->fatalError( $msg ); |
82 | } |
83 | $json = json_decode( $data, true ); |
84 | if ( $json === null ) { |
85 | $msg = sprintf( "Invalid json in the data file %s\n", $filename ); |
86 | $this->fatalError( $msg, 2 ); |
87 | } |
88 | return $json; |
89 | } |
90 | } |
91 | |
92 | // @codeCoverageIgnoreStart |
93 | $maintClass = GenerateUcfirstOverrides::class; |
94 | require_once RUN_MAINTENANCE_IF_MAIN; |
95 | // @codeCoverageIgnoreEnd |