public static function fromJsonLd(JsonObject $element)
    {
        if (false === property_exists($element, '@value')) {
            return false;
        }

        $value = $element->{'@value'};
        $type = (property_exists($element, '@type'))
            ? $element->{'@type'}
            : null;
        $language = (property_exists($element, '@language'))
            ? $element->{'@language'}
            : null;

        if (is_int($value) || is_float($value)) {
            if (($value != (int) $value) || (RdfConstants::XSD_DOUBLE === $type)) {
                $value = preg_replace('/(0{0,14})E(\+?)/', 'E', sprintf('%1.15E', $value));

                if ((null === $type) && (null === $language)) {
                    return new TypedValue($value, RdfConstants::XSD_DOUBLE);
                }
            } else {
                $value = sprintf('%d', $value);
                if ((null === $type) && (null === $language)) {
                    return new TypedValue($value, RdfConstants::XSD_INTEGER);
                }
            }
        } elseif (is_bool($value)) {
            $value = ($value) ? 'true' : 'false';

            if ((null === $type) && (null === $language)) {
                return new TypedValue($value, RdfConstants::XSD_BOOLEAN);
            }
        } elseif (false === is_string($value)) {
            return false;
        }

        // @type gets precedence
        if ((null === $type) && (null !== $language)) {
            return new LanguageTaggedString($value, $language);
        }

        return new TypedValue($value, (null === $type) ? RdfConstants::XSD_STRING : $type);
    }
public static function fromJsonLd(JsonObject $element)
    {
        if (false === property_exists($element, '@value')) {
            return false;
        }

        $value = $element->{'@value'};
        $type = (property_exists($element, '@type'))
            ? $element->{'@type'}
            : null;
        $language = (property_exists($element, '@language'))
            ? $element->{'@language'}
            : null;

        if (is_int($value) || is_float($value)) {
            if (($value != (int) $value) || (RdfConstants::XSD_DOUBLE === $type)) {
                $value = preg_replace('/(0{0,14})E(\+?)/', 'E', sprintf('%1.15E', $value));

                if ((null === $type) && (null === $language)) {
                    return new TypedValue($value, RdfConstants::XSD_DOUBLE);
                }
            } else {
                $value = sprintf('%d', $value);
                if ((null === $type) && (null === $language)) {
                    return new TypedValue($value, RdfConstants::XSD_INTEGER);
                }
            }
        } elseif (is_bool($value)) {
            $value = ($value) ? 'true' : 'false';

            if ((null === $type) && (null === $language)) {
                return new TypedValue($value, RdfConstants::XSD_BOOLEAN);
            }
        } elseif (false === is_string($value)) {
            return false;
        }

        // @type gets precedence
        if ((null === $type) && (null !== $language)) {
            return new LanguageTaggedString($value, $language);
        }

        return new TypedValue($value, (null === $type) ? RdfConstants::XSD_STRING : $type);
    }
public static function fromJsonLd ( JsonObject $ element ) { if ( false === property_exists ( $ element , '@value' ) ) { return false ; } $ value = $ element -> { '@value' } ; $ type = ( property_exists ( $ element , '@type' ) ) ? $ element -> { '@type' } : null ; $ language = ( property_exists ( $ element , '@language' ) ) ? $ element -> { '@language' } : null ; if ( is_int ( $ value ) || is_float ( $ value ) ) { if ( ( $ value != ( int ) $ value ) || ( RdfConstants :: XSD_DOUBLE === $ type ) ) { $ value = preg_replace ( '/(0{0,14})E(\+?)/' , 'E' , sprintf ( '%1.15E' , $ value ) ) ; if ( ( null === $ type ) && ( null === $ language ) ) { return new TypedValue ( $ value , RdfConstants :: XSD_DOUBLE ) ; } } else { $ value = sprintf ( '%d' , $ value ) ; if ( ( null === $ type ) && ( null === $ language ) ) { return new TypedValue ( $ value , RdfConstants :: XSD_INTEGER ) ; } } } elseif ( is_bool ( $ value ) ) { $ value = ( $ value ) ? 'true' : 'false' ; if ( ( null === $ type ) && ( null === $ language ) ) { return new TypedValue ( $ value , RdfConstants :: XSD_BOOLEAN ) ; } } elseif ( false === is_string ( $ value ) ) { return false ; } // @type gets precedence if ( ( null === $ type ) && ( null !== $ language ) ) { return new LanguageTaggedString ( $ value , $ language ) ; } return new TypedValue ( $ value , ( null === $ type ) ? RdfConstants :: XSD_STRING : $ type ) ; }
Create a LanguageTaggedString or TypedValue from a JSON-LD element

If the passed value element can't be transformed to a language-tagged
string or a typed value false is returned.

@param JsonObject $element The JSON-LD element

@return false|LanguageTaggedString|TypedValue The parsed object
Create a LanguageTaggedString or TypedValue from a JSON - LD element