MediaWiki master
Bidi.php
Go to the documentation of this file.
1<?php
8
10
28class Bidi {
29
33 public const LRE = "\xE2\x80\xAA";
34
38 public const RLE = "\xE2\x80\xAB";
39
43 public const PDF = "\xE2\x80\xAC";
44
52 public function __construct(
53 private readonly Provider $provider,
54 ) {
55 }
56
72 public function process( string $value ): string {
73 $dir = $this->provider->getBidiProvider()->getDirection( $value );
74 if ( $dir === 'ltr' ) {
75 # Wrap in LEFT-TO-RIGHT EMBEDDING ... POP DIRECTIONAL FORMATTING
76 return self::LRE . $value . self::PDF;
77 }
78 if ( $dir === 'rtl' ) {
79 # Wrap in RIGHT-TO-LEFT EMBEDDING ... POP DIRECTIONAL FORMATTING
80 return self::RLE . $value . self::PDF;
81 }
82
83 # No strong directionality: return the text unmodified
84 return $value;
85 }
86}
const PDF
Unicode POP DIRECTIONAL FORMATTING character (U+202C).
Definition Bidi.php:43
process(string $value)
Applies bidirectional formatting to the provided text.
Definition Bidi.php:72
__construct(private readonly Provider $provider,)
Initializes the Bidi handler with the provider.
Definition Bidi.php:52
const RLE
Unicode RIGHT-TO-LEFT EMBEDDING character (U+202B).
Definition Bidi.php:38
const LRE
Unicode LEFT-TO-RIGHT EMBEDDING character (U+202A).
Definition Bidi.php:33