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