ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Encoding.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Refinery\String\InvalidArgumentException;
27
28class Encoding implements Transformation
29{
32
33 public const UTF_8 = 'UTF-8';
34 public const ISO_8859_1 = 'ISO-8859-1';
35 public const US_ASCII = 'US-ASCII';
36
37 // More common names for the encodings
38 public const ASCII = self::US_ASCII;
39 public const LATIN_1 = self::ISO_8859_1;
40
41 public function __construct(
42 private string $from_encoding,
43 private string $to_encoding
44 ) {
45 }
46
47 public function transform($from): string
48 {
49 if (!is_string($from)) {
50 throw new InvalidArgumentException(__METHOD__ . " the argument is not a string.");
51 }
52
53 return mb_convert_encoding(
54 $from,
55 $this->to_encoding,
56 $this->from_encoding
57 );
58 }
59}
transform($from)
Perform the transformation.
Definition: Encoding.php:47
__construct(private string $from_encoding, private string $to_encoding)
Definition: Encoding.php:41
A transformation is a function from one datatype to another.