Файловый менеджер - Редактировать - /var/www/html/Punycode.zip
Ðазад
PK ! X�gde e ToPunycode.phpnu �[��� <?php namespace Algo26\IdnaConvert\Punycode; use Algo26\IdnaConvert\Exception\AlreadyPunycodeException; use Algo26\IdnaConvert\Exception\InvalidCharacterException; use Algo26\IdnaConvert\Exception\InvalidIdnVersionException; use Algo26\IdnaConvert\NamePrep\NamePrep; class ToPunycode extends AbstractPunycode implements PunycodeInterface { /** @var NamePrep */ private $namePrep; /** * @throws InvalidIdnVersionException */ public function __construct(?string $idnVersion = null) { $this->namePrep = new NamePrep($idnVersion); parent::__construct(); } /** * @param array $decoded * * @return string * @throws AlreadyPunycodeException * @throws InvalidCharacterException */ public function convert(array $decoded): string { // We cannot encode a domain name containing the Punycode prefix $checkForPrefix = array_slice($decoded, 0, self::$prefixLength); if (self::$prefixAsArray === $checkForPrefix) { throw new AlreadyPunycodeException('This is already a Punycode string', 100); } // We will not try to encode strings consisting of basic code points only $canEncode = false; foreach ($decoded as $k => $v) { if ($v > 0x7a) { $canEncode = true; break; } } if (!$canEncode) { return false; } // Do NAMEPREP $decoded = $this->namePrep->do($decoded); if (!$decoded || !is_array($decoded)) { return false; // NAMEPREP failed } $decodedLength = count($decoded); if (!$decodedLength) { return false; // Empty array } $codeCount = 0; // How many chars have been consumed $encoded = ''; // Copy all basic code points to output for ($i = 0; $i < $decodedLength; ++$i) { $test = $decoded[$i]; if (0x01 <= $test && $test <= 0x7f) { $encoded .= chr($decoded[$i]); $codeCount++; } } if ($codeCount === $decodedLength) { return $encoded; // All codepoints were basic ones } // Start with the prefix; copy it to output $encoded = self::punycodePrefix . $encoded; // If we have basic code points in output, add a hyphen to the end if ($codeCount > 0) { $encoded .= '-'; } // Now find and encode all non-basic code points $isFirst = true; $currentCode = self::initialN; $bias = self::initialBias; $delta = 0; while ($codeCount < $decodedLength) { $nextCode = self::maxUcs; // Find the next largest code point to $currentCode foreach ($decoded as $nextLargestCandidate) { if ($nextLargestCandidate >= $currentCode && $nextLargestCandidate <= $nextCode) { $nextCode = $nextLargestCandidate; } } $codeCountPlusOne = $codeCount + 1; $delta += ($nextCode - $currentCode) * $codeCountPlusOne; $currentCode = $nextCode; // Scan input again and encode all characters whose code point is $currentCode for ($i = 0; $i < $decodedLength; $i++) { if ($decoded[$i] < $currentCode) { $delta++; } if ($decoded[$i] === $currentCode) { for ($q = $delta, $k = self::base; 1; $k += self::base) { $t = ($k <= $bias) ? self::tMin : (($k >= $bias + self::tMax) ? self::tMax : $k - $bias ); if ($q < $t) { break; } $encoded .= $this->encodeDigit(intval($t + (($q - $t) % (self::base - $t)))); $q = (int) (($q - $t) / (self::base - $t)); } $encoded .= $this->encodeDigit($q); $bias = $this->adapt($delta, $codeCountPlusOne, $isFirst); $codeCount++; $delta = 0; $isFirst = false; } } $delta++; $currentCode++; } return $encoded; } /** * Encoding a certain digit * @param int $d * @return string */ private function encodeDigit($d): string { return chr($d + 22 + 75 * ($d < 26)); } } PK ! ����g g FromPunycode.phpnu �[��� <?php namespace Algo26\IdnaConvert\Punycode; use Algo26\IdnaConvert\Exception\InvalidCharacterException; use OutOfBoundsException; class FromPunycode extends AbstractPunycode implements PunycodeInterface { public function __construct(?string $idnVersion = null) { parent::__construct(); } /** * The actual decoding algorithm * * @param string * * @return mixed * @throws InvalidCharacterException */ public function convert($encoded) { if (!$this->validate($encoded)) { return false; } $decoded = []; // Find last occurrence of the delimiter $delimiterPosition = strrpos($encoded, '-'); if ($delimiterPosition > self::byteLength(self::punycodePrefix)) { for ($k = $this->byteLength(self::punycodePrefix); $k < $delimiterPosition; ++$k) { $decoded[] = ord($encoded[$k]); } } $decodedLength = count($decoded); $encodedLength = $this->byteLength($encoded); // Walking through the strings; init $isFirst = true; $bias = self::initialBias; $currentIndex = 0; $char = self::initialN; $startOfLoop = ($delimiterPosition) ? ($delimiterPosition + 1) : 0; for ($encodedIndex = $startOfLoop; $encodedIndex < $encodedLength; ++$decodedLength) { for ($oldIndex = $currentIndex, $w = 1, $k = self::base; 1; $k += self::base) { if ($encodedIndex + 1 > $encodedLength) { throw new InvalidCharacterException('trying to read beyond input length'); } $digit = $this->decodeDigit($encoded[$encodedIndex++]); if ($digit >= self::base) { throw new InvalidCharacterException( sprintf( 'encountered invalid digit at #%d', $encodedIndex - 1 ) ); } if ($digit > floor((PHP_INT_MAX - $currentIndex) / $w)) { throw new OutOfBoundsException( sprintf( 'overflow at #%d', $encodedIndex - 1 ) ); } $currentIndex += $digit * $w; $t = ($k <= $bias) ? self::tMin : ( ($k >= $bias + self::tMax) ? self::tMax : ($k - $bias) ); if ($digit < $t) { break; } $w = (int) ($w * (self::base - $t)); } $bias = $this->adapt($currentIndex - $oldIndex, $decodedLength + 1, $isFirst); $isFirst = false; $char += (int) ($currentIndex / ($decodedLength + 1)); $currentIndex %= ($decodedLength + 1); if ($decodedLength > 0) { // Make room for the decoded char for ($i = $decodedLength; $i > $currentIndex; $i--) { $decoded[$i] = $decoded[($i - 1)]; } } $decoded[$currentIndex++] = $char; } return $this->unicodeTransCoder->convert( $decoded, $this->unicodeTransCoder::FORMAT_UCS4_ARRAY, $this->unicodeTransCoder::FORMAT_UTF8 ); } /** * Checks, whether the provided string is a valid punycode string * @param string $encoded * @return boolean */ private function validate($encoded): bool { // Check for existence of the prefix if (strpos($encoded, self::punycodePrefix) !== 0) { return false; } // If nothing is left after the prefix, it is hopeless if (strlen(trim($encoded)) <= strlen(self::punycodePrefix)) { return false; } return true; } private function decodeDigit(string $codePoint): int { $codeAsInt = ord($codePoint); if ($codeAsInt - 48 < 10) { return $codeAsInt - 22; } if ($codeAsInt - 65 < 26) { return $codeAsInt - 65; } if ($codeAsInt - 97 < 26) { return $codeAsInt - 97; } return self::base; } } PK ! ���)� � AbstractPunycode.phpnu �[��� <?php namespace Algo26\IdnaConvert\Punycode; use Algo26\IdnaConvert\TranscodeUnicode\TranscodeUnicode; abstract class AbstractPunycode { const punycodePrefix = 'xn--'; const invalidUcs = 0x80000000; const maxUcs = 0x10FFFF; const base = 36; const tMin = 1; const tMax = 26; const skew = 38; const damp = 700; const initialBias = 72; const initialN = 0x80; protected static $isMbStringOverload; protected static $prefixAsArray; protected static $prefixLength; /** @var TranscodeUnicode */ protected $unicodeTransCoder; public function __construct() { $this->unicodeTransCoder = new TranscodeUnicode(); // populate mbstring overloading cache if not set if (self::$isMbStringOverload === null) { self::$isMbStringOverload = (extension_loaded('mbstring') && (ini_get('mbstring.func_overload') & 0x02) === 0x02); } if (self::$prefixAsArray === null) { self::$prefixAsArray = $this->unicodeTransCoder->convert( self::punycodePrefix, $this->unicodeTransCoder::FORMAT_UTF8, $this->unicodeTransCoder::FORMAT_UCS4_ARRAY ); self::$prefixLength = $this->byteLength(self::punycodePrefix); } } public function getPunycodePrefix(): string { return self::punycodePrefix; } /** * Gets the length of a string in bytes even if mbstring function * overloading is turned on * * @param string $string the string for which to get the length. * @return integer the length of the string in bytes. */ protected function byteLength($string): int { if (self::$isMbStringOverload) { return mb_strlen($string, '8bit'); } return strlen((string) $string); } /** * Adapt the bias according to the current code point and position * @param int $delta * @param int $nPoints * @param int $isFirst * @return int */ protected function adapt($delta, $nPoints, $isFirst): int { $delta = intval($isFirst ? ($delta / self::damp) : ($delta / 2)); $delta += intval($delta / $nPoints); for ($k = 0; $delta > ((self::base - self::tMin) * self::tMax) / 2; $k += self::base) { $delta = intval($delta / (self::base - self::tMin)); } return intval($k + (self::base - self::tMin + 1) * $delta / ($delta + self::skew)); } } PK ! �!Bg� � PunycodeInterface.phpnu �[��� <?php namespace Algo26\IdnaConvert\Punycode; interface PunycodeInterface { public function __construct(?string $idnVersion = null); public function getPunycodePrefix(); } PK ! X�gde e ToPunycode.phpnu �[��� PK ! ����g g � FromPunycode.phpnu �[��� PK ! ���)� � J$ AbstractPunycode.phpnu �[��� PK ! �!Bg� � |. PunycodeInterface.phpnu �[��� PK G w/
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка