Explorar el Código

:octocat: save/restore current mb_internal_encoding

codemasher hace 7 años
padre
commit
8b94aa6426
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  1. 17 0
      src/QRCode.php

+ 17 - 0
src/QRCode.php

@@ -98,17 +98,34 @@ class QRCode{
 	 */
 	protected $dataInterface;
 
+	/**
+	 * @see http://php.net/manual/function.mb-internal-encoding.php
+	 * @var string
+	 */
+	protected $mbCurrentEncoding;
+
 	/**
 	 * QRCode constructor.
 	 *
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
 	 */
 	public function __construct(SettingsContainerInterface $options = null){
+		// save the current mb encoding (in case it differs from UTF-8)
+		$this->mbCurrentEncoding = mb_internal_encoding();
+		// use UTF-8 from here on
 		mb_internal_encoding('UTF-8');
 
 		$this->options = $options ?? new QROptions;
 	}
 
+	/**
+	 * @return void
+	 */
+	public function __destruct(){
+		// restore the previous mb_internal_encoding, so that we don't mess up the rest of the script
+		mb_internal_encoding($this->mbCurrentEncoding);
+	}
+
 	/**
 	 * Renders a QR Code for the given $data and QROptions
 	 *