aboutsummaryrefslogtreecommitdiff
path: root/engine/SkinString.php
blob: 0f8f14d1f2621bb2efe38a2d625ed2c333d3ccfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

class SkinString implements Stringable {

    protected SkinStringModificationType $modType;

    public function __construct(protected string $string) {}

    public function setModType(SkinStringModificationType $modType) {
        $this->modType = $modType;
    }

    public function __toString(): string {
        return match ($this->modType) {
            SkinStringModificationType::HTML => htmlescape($this->string),
            SkinStringModificationType::URL => urlencode($this->string),
            SkinStringModificationType::JSON => json_encode($this->string, JSON_UNESCAPED_UNICODE),
            SkinStringModificationType::ADDSLASHES => addslashes($this->string),
            default => $this->string,
        };
    }

}