- md5
- 689642cf9cde47b57f78a2d7d1219334
- sha1
- fed29e29cd2189b0aaa6e7fe504d3c27836f897f
- sha256
- 56250b05389ec87fb70eae972ae545c0a1bfdaf9dfdae0327a93de2163d4afb8
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
<?php
declare(strict_types=1);
namespace SpomkyLabs\Pki\X501\StringPrep;
/**
* Implement Internationalized String Preparation as specified by RFC 4518.
*
* @see https://tools.ietf.org/html/rfc4518
*/
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;
/**
* @param PrepareStep[] $_steps Preparation steps to apply
*/
private function __construct(
/**
* Preparation steps.
*/
private array $_steps
) {
}
/**
* Get default instance for given string type.
*
* @param int $string_type ASN.1 string type tag.
*/
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(),
// @todo Vary by string type
self::STEP_INSIGNIFICANT_CHARS => new InsignificantNonSubstringSpaceStep(),
];
return new self($steps);
}
/**
* Get self with case folding set.
*
* @param bool $fold True to apply case folding
*/
public function withCaseFolding(bool $fold): self
{
$obj = clone $this;
$obj->_steps[self::STEP_MAP] = MapStep::create($fold);
return $obj;
}
/**
* Prepare string.
*/
public function prepare(string $string): string
{
foreach ($this->_steps as $step) {
$string = $step->apply($string);
}
return $string;
}
}
The same content is in 32 releases, Joomla 6.1.0-alpha2 to 6.3.0-alpha1. See them all, or every version of this file.