AVClient::_encode, internal method for encoding object values.

@param mixed $value Value to encode
@param bool $allowAVObjects Allow nested objects

@return mixed Encoded results.

@throws \Exception
@ignore
486352
public static function _encode($value, $allowAVObjects)
    {
        if ($value instanceof \DateTime)
        {
            return array(
                '__type' => 'Date',
                'iso'    => self::getProperDateFormat($value)
            );
        }

        if ($value instanceof \stdClass)
        {
            return $value;
        }

        if ($value instanceof AVObject)
        {
            if (!$allowAVObjects)
            {
                throw new \Exception('AVObjects not allowed here.');
            }

            return $value->_toPointer();
        }

        if ($value instanceof Encodable)
        {
            return $value->_encode();
        }

        if (is_array($value))
        {
            return self::_encodeArray($value, $allowAVObjects);
        }

        if (!is_scalar($value) && $value !== null)
        {
            throw new \Exception('Invalid type encountered.');
        }

        return $value;
    }
1259602
public function cast($value, array $properties)
    {
        [$type, $length, $nullable] = $properties;

        // nullable?
        if ($value === null && $nullable) {
            return $value;
        }

        // int, float, bool
        switch ($type) {
            case 'int': return (int) $value;
            case 'float': return (float) $value;
            case 'bool': return ($value === 't') ? true : false;
        }

        // bit
        if ($this->mapOptions['bool'] && $type == 'bit' && $length == 1) {
            // bool cast
            $value = (string) $value;
            if ($value === '0' || $value === '1') { // @important
                return (bool) $value;
            }
        }

        return $value;
    }
1371767
protected function unserialize($value)
    {
        if (!is_array($value)) {
            return $value;
        } else {
            if (($value['__rialto_error__'] ?? false) === true) {
                return new Exception($value, $this->options['debug']);
            } else if (($value['__rialto_resource__'] ?? false) === true) {
                if ($this->delegate instanceof ShouldHandleProcessDelegation) {
                    $classPath = $this->delegate->resourceFromOriginalClassName($value['class_name'])
                        ?: $this->delegate->defaultResource();
                } else {
                    $classPath = $this->defaultResource();
                }

                $resource = new $classPath;

                if ($resource instanceof ShouldIdentifyResource) {
                    $resource->setResourceIdentity(new ResourceIdentity($value['class_name'], $value['id']));
                }

                if ($resource instanceof ShouldCommunicateWithProcessSupervisor) {
                    $resource->setProcessSupervisor($this);
                }

                return $resource;
            } else {
                return array_map(function ($value) {
                    return $this->unserialize($value);
                }, $value);
            }
        }
    }
486328
public static function toByteString($value)
    {
        if (self::isStringCastable($value)) {
            return (string)$value;
        } else {
            throw new \InvalidArgumentException(ErrorMessageCreator::create($value, 'ByteString (a string)'));
        }
    }
966399
public static function ConvertEncoding($value, $to, $from)
	{
		if (self::getIsIconvEnabled()) {
			return iconv($from, $to, $value);
		}

		if (self::getIsMbstringEnabled()) {
			return mb_convert_encoding($value, $to, $from);
		}

		if($from == 'UTF-16LE'){
			return self::utf16_decode($value, false);
		}else if($from == 'UTF-16BE'){
			return self::utf16_decode($value);
		}
		// else, no conversion
		return $value;
	}
464305
public static function encode($value)
    {
        $encoded = json_encode($value, JSON_UNESCAPED_UNICODE);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(sprintf(
                'Could not encode value into json. Error %s and message %s',
                json_last_error(),
                json_last_error_msg()
            ));
        }

        return $encoded;
    }
1206284
public function encode($value)
    {
        switch (true) {
            case is_null($value):
                return $this->encodeString('', self::T_NULL);
            case is_bool($value):
                return $this->encodeString($value ? 'true' : 'false', self::T_BOOL);
            case is_int($value):
                return $this->encodeString($value, self::T_INT);
            case is_float($value):
                return $this->encodeString($value, self::T_FLOAT);
            case is_array($value):
                return $this->encodePHPArray($value);

            case is_resource($value):
                throw new InvalidArgumentException("You can't encode a PHP resource as a tagged netstring.");

            default:
                return $this->encodeString($value);
        }
    }
683270
public function makeArrayFieldValue($value)
    {
        $value = $this->_unserializeValue($value);
        if (!$this->_isEncodedArrayFieldValue($value)) {
            $value = $this->_encodeArrayFieldValue($value);
        }

        return $value;
    }
945582
public function encrypt($value, $serialize = true)
    {
        $iv = self::randomBytes(openssl_cipher_iv_length($this->cipher));

        // First we will encrypt the value using OpenSSL. After this is encrypted we
        // will proceed to calculating a MAC for the encrypted value so that this
        // value can be verified later as not having been changed by the users.
        $value = \openssl_encrypt(
            $serialize ? serialize($value) : $value,
            $this->cipher, $this->key, 0, $iv
        );

        if ($value === false) {
            throw new \Exception('Could not encrypt the data.');
        }

        // Once we get the encrypted value we'll go ahead and base64_encode the input
        // vector and create the MAC for the encrypted value so we can then verify
        // its authenticity. Then, we'll JSON the data into the "payload" array.
        $mac = $this->hash($iv = base64_encode($iv), $value);

        $json = json_encode(compact('iv', 'value', 'mac'));

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception('Could not encrypt the data.');
        }

        return base64_encode($json);
    }
1225285
public function rawurl($value, array $options, $mode) {
        if ($mode === self::TO && $options['encode']) {
            return rawurlencode($value);
        }

        if ($mode === self::FROM && $options['decode']) {
            return rawurldecode($value);
        }

        return $value;
    }
285289
private function encode($value)
    {
        if ($value === true)
            $value = "true";
        else if ($value === false)
            $value = "false";
        else if (is_string($value))
            $value = "\"$value\"";
        return $value;
    }
239580
public static function Base64Encode ($value, $options = []) {
		$to_encoding = isset($options['to_encoding']) ? $options['to_encoding'] : false;
		if ($to_encoding !== false) {
			$from_encoding = isset($options['from_encoding']) ? $options['from_encoding'] : static::DEFAULT_ENCODING;
			$value = mb_convert_encoding($value, $to_encoding, $from_encoding);
		}
		return base64_encode($value);
	}
8369
protected function encode($value)
    {
        try {
            return $this->encoders->getEncoderForValue($value)
                ->encode($value, new EncodingContext());
        } catch (EncodingException | InvalidArgumentException | OutOfBoundsException $ex) {
            throw new SerializationException('Failed to serialize value', 0, $ex);
        }
    }
990122
public function map(ValueObject $value)
    {
        if (!$value instanceof ContentMetadataUpdateStruct) {
            throw new InvalidArgumentException('value', sprintf('must be an instance of %s', ContentMetadataUpdateStruct::class));
        }

        $data = new MainTranslationUpdateData();
        $data->setLanguageCode($value->mainLanguageCode);

        return $data;
    }
801681
public static function encode($value, $options = JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK)
    {
        if ($value instanceof \Traversable)
        {
            $value = \iterator_to_array($value);
        }

        return \json_encode($value, $options);
    }
881602
public function encodeValue($value)
    {
        if ($this->urlEncode == self::RFC_3986) {
            return rawurlencode($value);
        } elseif ($this->urlEncode == self::FORM_URLENCODED) {
            return urlencode($value);
        } else {
            return (string) $value;
        }
    }
1019876
public function encode($value)
    {
        if ($value === '' || !is_scalar($value)) {
            return false;
        }

        $text = $value;
        $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
        $cryptText = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->secureKey, $text, MCRYPT_MODE_ECB, $iv);

        return trim($this->safeBase64Encode($cryptText));
    }