LdapTools\Utilities\TSProperty::encodePropValue PHP Метод

encodePropValue() защищенный Метод

Get the encoded property value as a binary blob.
protected encodePropValue ( string $value, boolean $string = false ) : string
$value string
$string boolean
Результат string
    protected function encodePropValue($value, $string = false)
    {
        // An int must be properly padded. (then split and reversed). For a string, we just split the chars. This seems
        // to be the easiest way to handle UTF-8 characters instead of trying to work with their hex values.
        $chars = $string ? MBString::str_split($value) : array_reverse(str_split($this->dec2hex($value, 8), 2));
        $encoded = '';
        foreach ($chars as $char) {
            // Get the bits for the char. Using this method to ensure it is fully padded.
            $bits = sprintf('%08b', $string ? MBString::ord($char) : hexdec($char));
            $nibbleX = substr($bits, 0, 4);
            $nibbleY = substr($bits, 4, 4);
            // Construct the value with the header, high nibble, then low nibble.
            $value = self::NIBBLE_HEADER;
            foreach (['Y' => $nibbleY, 'X' => $nibbleX] as $nibbleType => $nibble) {
                $value .= $this->getNibbleWithControl($nibbleType, $nibble);
            }
            // Convert it back to a binary bit stream
            foreach ([0, 8, 16] as $start) {
                $encoded .= $this->packBitString(substr($value, $start, 8), 8);
            }
        }
        return $encoded;
    }