FluidTYPO3\Vhs\ViewHelpers\Format\Json\EncodeViewHelper::encodeValue PHP Method

encodeValue() protected method

protected encodeValue ( string $value, boolean $useTraversableKeys, boolean $preventRecursion, string $recursionMarker, string $dateTimeFormat ) : mixed
$value string
$useTraversableKeys boolean
$preventRecursion boolean
$recursionMarker string
$dateTimeFormat string
return mixed
    protected function encodeValue($value, $useTraversableKeys, $preventRecursion, $recursionMarker, $dateTimeFormat)
    {
        if (true === $value instanceof \Traversable) {
            // Note: also converts ObjectStorage to \Vendor\Extname\Domain\Model\ObjectType[] which are each converted
            $value = iterator_to_array($value, $useTraversableKeys);
        } elseif (true === $value instanceof DomainObjectInterface) {
            // Convert to associative array,
            $value = $this->recursiveDomainObjectToArray($value, $preventRecursion, $recursionMarker);
        } elseif (true === $value instanceof \DateTime) {
            $value = $this->dateTimeToUnixtimeMiliseconds($value, $dateTimeFormat);
        }
        // process output of conversion, catching specially supported object types such as DomainObject and DateTime
        if (true === is_array($value)) {
            $value = $this->recursiveArrayOfDomainObjectsToArray($value, $preventRecursion, $recursionMarker);
            $value = $this->recursiveDateTimeToUnixtimeMiliseconds($value, $dateTimeFormat);
        }
        $json = json_encode($value, JSON_HEX_AMP | JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new Exception('The provided argument cannot be converted into JSON.', 1358440181);
        }
        return $json;
    }