Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Component | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
parseTemplate | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
16 | * |
17 | * @file |
18 | */ |
19 | namespace MediaWiki\Skin\WikimediaApiPortal\Component; |
20 | |
21 | use MediaWiki\Skin\WikimediaApiPortal\TemplateParser; |
22 | |
23 | abstract class Component { |
24 | /** @var string */ |
25 | protected $templateName; |
26 | |
27 | /** @var ?array */ |
28 | protected $args; |
29 | |
30 | /** |
31 | * @param string $templateName |
32 | */ |
33 | public function __construct( string $templateName ) { |
34 | $this->templateName = $templateName; |
35 | } |
36 | |
37 | /** |
38 | * @param TemplateParser $templateParser |
39 | * @return ?string |
40 | */ |
41 | public function parseTemplate( TemplateParser $templateParser ): ?string { |
42 | if ( !$this->args ) { |
43 | return null; |
44 | } |
45 | $parsedArgs = []; |
46 | foreach ( $this->args as $key => $arg ) { |
47 | $parsedArgs[$key] = is_subclass_of( $arg, self::class ) |
48 | ? $arg->parseTemplate( $templateParser ) |
49 | : $arg; |
50 | } |
51 | return $templateParser->processTemplate( $this->templateName, $parsedArgs ); |
52 | } |
53 | } |