Get the encoded property value as a binary blob.

@param string $value
@param bool   $string

@return string
192425
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::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;
    }
329087
public static function binary($name, $value)
    {
        return new self($name, $value, '', true, false, false, true);
    }
585314
private function getValueAsString($value): string
    {
        if (is_bool($value)) {
            return $value ? 'true' : 'false';
        }

        if (is_float($value)) {
            $value = (string) $value;
            if (false === strpos($value, '.')) {
                $value .= '.0';
            }

            return $value;
        }

        if (is_int($value)) {
            return (string) $value;
        }

        throw new \InvalidArgumentException(sprintf('Unsupported data type: %s', gettype($value)));
    }
1332115
private function valueToString($value): string
    {
        // null
        if ($value === null) {
            return 'NULL';
        }

        // bool
        if (\is_bool($value)) {
            return $value ? 'TRUE' : 'FALSE';
        }

        // array
        if (\is_array($value)) {
            return 'Array';
        }

        // scalar types (integer, float, string)
        if (\is_scalar($value)) {
            return (string) $value;
        }

        // resource
        if (\is_resource($value)) {
            return \get_resource_type($value) . ' resource #' . (int) $value;
        }

        // object
        return \get_class($value) . ' Object';
    }
677207
private function stringify($value)
    {
        if (is_bool($value)) {
            return $value ? '<TRUE>' : '<FALSE>';
        } elseif (is_scalar($value)) {
            $val = (string) $value;

            if (strlen($val) > 100) {
                $val = substr($val, 0, 97).'...';
            }

            return $val;
        } elseif (is_array($value)) {
            return '<ARRAY>';
        } elseif (is_object($value)) {
            return sprintf('%s [%s]', get_class($value), spl_object_hash($value));
        } elseif (is_resource($value)) {
            return '<RESOURCE>';
        } elseif (is_null($value)) {
            return '<NULL>';
        } else {
            return 'unknown';
        }
    }
1035037
protected function getStringValue($value)
    {
        if ($value === true) {
            return 'true';
        } elseif ($value === false) {
            return 'false';
        } elseif ($value === null) {
            return 'null';
        } elseif (is_string($value)) {
            return "\"$value\"";
        }

        return rtrim(print_r($value, true));
    }
1174969
public function encode($value)
    {
        $encryptedValue = $this->getEncryptor()->encrypt($value);
        $encodedValue = base64_encode($encryptedValue);

        return $encodedValue;
    }
95373
public static function toBool($string)
    {
        if (null === $string) {
            return null;
        }

        return in_array(strtolower($string), self::$booleanTrue);
    }
1159505
private static function decode_value($value, $encoding)
    {
        switch (strtolower($encoding)) {
        case 'quoted-printable':
            self::$values_decoded = true;
            return quoted_printable_decode($value);

        case 'base64':
        case 'b':
            self::$values_decoded = true;
            return base64_decode($value);

        default:
            return $value;
        }
    }
485665
protected function databaseValue($value)
    {
        if (is_string($value)) {
            return $value;
        }

        if (!$value instanceof BinaryValue) {
            if (!is_resource($value) && !$value instanceof StreamInterface) {
                throw ODMException::invalidValueForType('Binary', ['string', 'resource', 'StreamInterface', 'BinaryValue', 'null'], $value);
            }

            $value = \GuzzleHttp\Psr7\stream_for($value);
        }

        return (string)$value;
    }
536952
public static function string($value='', bool $flatten=false) {
		ref\cast::string($value, $flatten);
		return $value;
	}
1365419
public function dump($value) : string
    {
        if (! is_bool($value))
            throw new DumpException($this, $value, self::DUMP_ERROR);

        return $value ? 'true' : 'false';
    }
1343248
public static function boolval( $value )
    {
        if ( \is_bool( $value ) )
        {
            return $value;
        }

        $_value = \strtolower( (string)$value );

        //	FILTER_VALIDATE_BOOLEAN doesn't catch 'Y' or 'N', so convert to full words...
        if ( 'y' == $_value )
        {
            $_value = 'yes';
        }
        elseif ( 'n' == $_value )
        {
            $_value = 'no';
        }

        return \filter_var( $_value, FILTER_VALIDATE_BOOLEAN );
    }
950544
private static function encodeBoolean($bool)
    {
        if ($bool)
        {
            return self::encodeFirstByte(MajorType::SIMPLE_AND_FLOAT, AdditionalType::SIMPLE_TRUE);
        }
        else
        {
            return self::encodeFirstByte(MajorType::SIMPLE_AND_FLOAT, AdditionalType::SIMPLE_FALSE);
        }
    }
1373967
public function dump($value)
    {
        switch (gettype($value)) {
            // Handle boolean values.
            case "boolean": {
                $output = $value ? "true" : "false";

                // You can represent booleans (and NULLs) in either lower- or uppercase format.
                return $this->config["bool_lowercase"] ? $output : strtoupper($output);
            }

            // Handle NULL values.
            case "NULL": {
                return $this->config["null_lowercase"] ? "null" : "NULL";
            }

            // Handle integers.
            case "integer": {
                return (string) $value;
            }

            // Handle floats (doubles).
            case "double": {
                // Dumpy allows you to round floats to round_double decimal points.
                if ($this->config["round_double"] !== false) {
                    $value = round($value, $this->config["round_double"], PHP_ROUND_HALF_UP);
                }

                return (string) $value;
            }

            // Handle strings.
            case "string": {
                // @suggestion Multibyte support?
                // Look above for the detailed explanation.
                if (strlen($value) > $this->config["str_max_length"]) {
                    $value = substr($value, 0, $this->config["str_max_length"]) . "...";
                }

                // Dumpy allows you to replace newline characters with "\\n".
                if ($this->config["replace_newline"]) {
                    $value = str_replace(PHP_EOL, "\\n", $value);
                }

                return "\"{$value}\"";
            }

            // Handle arrays.
            case "array": {
                return $this->printArray($value) . PHP_EOL;
            }

            // Handle objects.
            case "object": {
                return $this->printObject($value);
            }
            // @codeCoverageIgnoreStart
        }
    }
1313065
public function decode($value)
    {
        if (false === array_key_exists($value, $this->values)) {
            return false;
        }

        return $this->values[$value];
    }
81817
public static function decode(string $value)
    {
        $stdObject = json_decode($value);
        // catch error if it occurs
        self::catchError();

        if (self::getError()) {
            return self::getError();
        }

        return $stdObject;
    }