<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\X501\StringPrep; final class StringPreparer { final public const STEP_TRANSCODE = 1; final public const STEP_MAP = 2; final public const STEP_NORMALIZE = 3; final public const STEP_PROHIBIT = 4; final public const STEP_CHECK_BIDI = 5; final public const STEP_INSIGNIFICANT_CHARS = 6; private function __construct( private array $_steps ) { } public static function forStringType(int $string_type): self { $steps = [ self::STEP_TRANSCODE => TranscodeStep::create($string_type), self::STEP_MAP => MapStep::create(), self::STEP_NORMALIZE => new NormalizeStep(), self::STEP_PROHIBIT => new ProhibitStep(), self::STEP_CHECK_BIDI => new CheckBidiStep(), self::STEP_INSIGNIFICANT_CHARS => new InsignificantNonSubstringSpaceStep(), ]; return new self($steps); } public function withCaseFolding(bool $fold): self { $obj = clone $this; $obj->_steps[self::STEP_MAP] = MapStep::create($fold); return $obj; } public function prepare(string $string): string { foreach ($this->_steps as $step) { $string = $step->apply($string); } return $string; } } 