MediaWiki fundraising/REL1_35
EncodingMangler.php
Go to the documentation of this file.
1<?php
26 protected $use_transliterator = false;
27 protected $transliterator;
28
29 public function __construct() {
30 if ( class_exists( Transliterator::class ) ) {
31 $this->use_transliterator = true;
32 // Use Any-Latin to munge Cyrillic, Kanji, etc
33 // Then convert anything outside the ISO-8859-1 range to nearest ASCII
34 $this->transliterator = Transliterator::create( 'Any-Latin; [^a-ΓΏ] Latin-ASCII' );
35 }
36 }
37
38 public function stage( GatewayType $adapter, $normalized, &$stagedData ) {
39 foreach ( array_keys( $stagedData ) as $key ) {
40 $stagedData[$key] = $this->transliterate( $stagedData[$key] );
41 }
42 }
43
50 public function transliterate( $value ) {
51 if ( $this->use_transliterator ) {
52 return $this->transliterator->transliterate( $value );
53 }
54 $iso = iconv( 'UTF-8', 'ISO-8859-1//TRANSLIT', $value );
55 return iconv( 'ISO-8859-1', 'UTF-8', $iso );
56 }
57}
Wikimedia Foundation.
transliterate( $value)
Forces string into ISO-8859-1 space.
stage(GatewayType $adapter, $normalized, &$stagedData)
Transform a subset of normalized data into the "staged" data expected by a payment processor.
GatewayType Interface.
Used to mark any class which implements an staging method, for transforming data into the form expect...