Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / parser / PPDStackElement_Hash.php
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 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Parser
20 */
21
22 /**
23 * @ingroup Parser
24 * @property PPDPart_Hash[] $parts
25 */
26 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
27 class PPDStackElement_Hash extends PPDStackElement {
28
29 public function __construct( $data = [] ) {
30 $this->partClass = PPDPart_Hash::class;
31 parent::__construct( $data );
32 }
33
34 /**
35 * Get the accumulator that would result if the close is not found.
36 *
37 * @param int|bool $openingCount
38 * @return array
39 * @suppress PhanParamSignatureMismatch
40 */
41 public function breakSyntax( $openingCount = false ) {
42 if ( $this->open == "\n" ) {
43 $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out );
44 } else {
45 if ( $openingCount === false ) {
46 $openingCount = $this->count;
47 }
48 $s = substr( $this->open, 0, -1 );
49 $s .= str_repeat(
50 substr( $this->open, -1 ),
51 $openingCount - strlen( $s )
52 );
53 $accum = [ $this->savedPrefix . $s ];
54 $lastIndex = 0;
55 $first = true;
56 foreach ( $this->parts as $part ) {
57 if ( $first ) {
58 $first = false;
59 } elseif ( is_string( $accum[$lastIndex] ) ) {
60 $accum[$lastIndex] .= '|';
61 } else {
62 $accum[++$lastIndex] = '|';
63 }
64
65 foreach ( $part->out as $node ) {
66 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
67 $accum[$lastIndex] .= $node;
68 } else {
69 $accum[++$lastIndex] = $node;
70 }
71 }
72 }
73 }
74 return $accum;
75 }
76 }