| 1 |
<?php |
| 2 |
declare( strict_types = 1 ); |
| 3 |
|
| 4 |
namespace Wikimedia\Parsoid\Html2Wt; |
| 5 |
|
| 6 |
/** |
| 7 |
* Stack and helpers to enforce single-line context while serializing. |
| 8 |
*/ |
| 9 |
class SingleLineContext { |
| 10 |
// PORT-TODO document |
| 11 |
|
| 12 |
private array $stack = []; |
| 13 |
|
| 14 |
public function enforce(): void { |
| 15 |
$this->stack[] = true; |
| 16 |
} |
| 17 |
|
| 18 |
public function enforced(): bool { |
| 19 |
return count( $this->stack ) > 0 && end( $this->stack ); |
| 20 |
} |
| 21 |
|
| 22 |
public function disable(): void { |
| 23 |
$this->stack[] = false; |
| 24 |
} |
| 25 |
|
| 26 |
public function pop(): void { |
| 27 |
array_pop( $this->stack ); |
| 28 |
} |
| 29 |
|
| 30 |
} |