1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php
namespace Gedcomx\Rs\Client\Util;
/**
* A decorator class to wrap the multiple class types that can exist
* in the ML\JsonLD\Quad object property and give them consistent
* accessor methods that can handle possible errors in the RDF data.
*
* Class RdfNode
* @package Gedcomx\Rs\Client\Util
*/
class RdfNode
{
const IRI = 'ML\IRI\IRI';
const TYPED = 'ML\JsonLD\TypedValue';
const LANG = 'ML\JsonLD\LanguageTaggedString';
/**
* Gets the value for the specified node.
* @param mixed $node
*
* @return string|null
*/
public static function getValue($node)
{
$class = get_class($node);
switch ($class) {
case self::IRI:
return (string)$node;
case self::TYPED:
case self::LANG:
return $node->getValue();
default:
return null;
}
}
/**
* Gets the language value for the specified node.
*
* @param mixed $node
*
* @return null|string
*/
public static function getLanguage($node)
{
$class = get_class($node);
if ($class == self::LANG) {
return strtolower($node->getLanguage());
}
return null;
}
}