Debian Codegraph @

extensions/Math/src/WikiTexVC/MMLnodes/MMLbase.php

raw symbols SCIP
1 <?php
2 namespace MediaWiki\Extension\Math\WikiTexVC\MMLnodes;
3
4 use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\Tag;
5 use MediaWiki\Html\Html;
6
7 class MMLbase {
8 private string $name;
9 private array $attributes;
10
11 public function __construct( string $name, string $texclass = '', array $attributes = [] ) {
12 $this->name = $name;
13 $this->attributes = $attributes;
14 if ( $texclass !== '' ) {
15 $this->attributes[ TAG::CLASSTAG ] = $texclass;
16 }
17 }
18
19 public function name(): string {
20 return $this->name;
21 }
22
23 /**
24 * Encapsulating the input structure with start and end element
25 *
26 * @param string $input The raw HTML contents of the element: *not* escaped!
27 * @return string <tag> input </tag>
28 */
29 public function encapsulateRaw( string $input ): string {
30 return HTML::rawElement( $this->name, $this->attributes, $input );
31 }
32
33 /**
34 * Encapsulating the input with start and end element
35 *
36 * @param string $input
37 * @return string <tag> input </tag>
38 */
39 public function encapsulate( string $input = '' ): string {
40 return HTML::element( $this->name, $this->attributes, $input );
41 }
42
43 /**
44 * Getting the start element
45 * @return string
46 */
47 public function getStart(): string {
48 return HTML::openElement( $this->name, $this->attributes );
49 }
50
51 /**
52 * Gets an empty element with the specified name.
53 * Example: "<mrow/>"
54 * @return string
55 */
56 public function getEmpty(): string {
57 return substr( $this->getStart(), 0, -1 )
58 . '/>';
59 }
60
61 /**
62 * Getting the end element
63 * @return string
64 */
65 public function getEnd(): string {
66 return HTML::closeElement( $this->name );
67 }
68 }