@param array|\JsonSerializable $value

@throws InvalidArgumentException When the value cannot be json-encoded
968948
private static function jsonEncode($value, int $flags = null, int $maxDepth = 512): string
    {
        $flags = $flags ?? (JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRESERVE_ZERO_FRACTION);

        if (!\is_array($value) && !$value instanceof \JsonSerializable) {
            throw new InvalidArgumentException(sprintf('Option "json" must be array or JsonSerializable, %s given.', \is_object($value) ? \get_class($value) : \gettype($value)));
        }

        try {
            $value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0), $maxDepth);
        } catch (\JsonException $e) {
            throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
        }

        if (\PHP_VERSION_ID < 70300 && JSON_ERROR_NONE !== json_last_error() && (false === $value || !($flags & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
            throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', json_last_error_msg()));
        }

        return $value;
    }
120865
protected function serializeValue($value)
    {
        if (is_string($value)) {
            return $value;
        }
        if (is_object($value) || is_array($value)) {
            return json_encode($value);
        }
    }
47520
protected function jsonDecode($value, $errorMessage = null) {
        $decoded = json_decode($value, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new InvalidArgumentException(
                $errorMessage ?: 'The supplied parameter is not a valid JSON object.'
            );
        }

        return $decoded;
    }
1221836
public static function encode($value)
    {
        $encoded = self::safeEncode($value);
        $lastErrorCode = self::lastError();
        if ($lastErrorCode !== JSON_ERROR_NONE || $encoded === false) {
            throw new JsonEncodeException(self::lastErrorMessage(), $lastErrorCode);
        }
        return $encoded;
    }
136431
public function offsetSet($offset, $value): void
    {
        if (null === $offset) {
            throw new \InvalidArgumentException('Class `Common\Container\ArrayAccess` support only associative arrays');
        }
        $this->doSetContainer($offset, $value);
    }
559689
public function setJsonValue(array $value)
    {
        // Removing colons from value.
        $value = str_replace(
            ':',
            '',
            $value
        );

        if (1 === count($value)) {
            $this->setValue(reset($value));
        } else {
            $this->setValue($value);
        }
    }
703223
public static function allToArray($value)
    {
        if ($value instanceof \Traversable) {
            $value = iterator_to_array($value);
        }

        if (is_object($value)) {
            $value = get_object_vars($value);
        }

        $value = (array) $value;

        foreach ($value as $k => $v) {
            if (!static::isValidValue($v)) {
                throw new \InvalidArgumentException('Value :' . $value . ' is invalid.');
            }
        }

        return $value;
    }
166345
public static function encode($value, int $options = null) : string
    {
        if ($options) {
            $encoded = json_encode($value, $options);
        } else {
            $encoded = json_encode($value);
        }

        if (!is_string($encoded)) {
            throw new \InvalidArgumentException(sprintf(
                "Json encode failed (%s) with '%s' and type '%s'",
                json_last_error(),
                json_last_error_msg(),
                gettype($encoded)
            ));
        }

        return $encoded;
    }
455443
function offsetSet($offset, $value)
    {
        if (!$value instanceof Attribute) {
            throw new InvalidArgumentException(
                "Value is not an instance of \\Sirel\\Attribute"
            );
        }
        $this->attributes[$offset] = $value;
    }
484611
public function offsetSet($offset, $value)
    {
        if ($offset === '' || $offset === null) {
            throw new \InvalidArgumentException('The key of a collection must always be set');
        }

        $this->items[$offset] = $value;
    }
963167
public function encode($value)
    {
        $json = json_encode($value);

        if ($code = json_last_error()) $this->throwError($code);

        return $json;
    }
353051
public function offsetSet($offset, $value): void
    {
        if ($offset === null) {
            throw new InvalidArgumentException(
                'Map elements are key/value pairs; a key must be provided for '
                . 'value ' . $value
            );
        }

        $this->data[$offset] = $value;
    }
226329
public function setValues($values)
    {
        if ((null !== $values) && (false === is_array($values))) {
            if (false === ($values instanceof ArrayAccess)) {
                throw new InvalidArgumentException(
                    'The value of $values is not an array or an instance of ArrayAccess.'
                );
            }
        }

        $this->values = $values;
    }
1053989
public function convertJsonToArray($value) {

		if(true === $this -> convert_json) {

			if(true === is_string($value)) {

				$tmp = @json_decode($value, true);

				if(true === (json_last_error() == JSON_ERROR_NONE)) {
					$value = $tmp;
				}
			}
		}

		return $value;
	}
609436
public static function isNullOrArray($value, $message = null)
    {
        if (!is_null($value) && !is_array($value)) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected null or array, but got %s',
                Helper::typeToString($value)
            ));
        }
    }
223948
protected function castValueAsJson($value)
    {
        $value = $this->asJson($value);

        if ($value === false) {
            throw new \RuntimeException(
                sprintf(
                    "Unable to encode value [%s] for element [%s] to JSON: %s.",
                    $this->getName(),
                    get_class($this),
                    json_last_error_msg()
                )
            );
        }

        return $value;
    }
1276940
public function addValue($value)
    {
        if ($this->datatype == 'string') {
            if (is_string($value) == false) {
                throw new InvalidArgumentException('The value(' . $value . ') is not string but the restriction demands it');
            }
        } elseif ($this->datatype == 'integer') {
            // The value comes as string from the wsdl
            if (is_string($value)) {
                $value = intval($value);
            }

            if (is_int($value) == false) {
                throw new InvalidArgumentException('The value(' . $value . ') is not int but the restriction demands it');
            }
        } else {
            if ($value == null) {
                throw new InvalidArgumentException('Value(' . $value . ') is null');
            }
        }

        $this->values[] = $value;
    }