Check that a value parameter is valid, and convert it to an associative array if needed @ignore
protected function checkValueParam(&$value) {
if (isset($value)) {
if (is_object($value)) {
if (method_exists($value, 'toArray')) {
$value = $value
->toArray();
}
else {
throw new InvalidArgumentException("\$value should respond to the method toArray()");
}
}
elseif (is_array($value)) {
if (!isset($value['type'])) {
throw new InvalidArgumentException("\$value is missing a 'type' key");
}
if (!isset($value['value'])) {
throw new InvalidArgumentException("\$value is missing a 'value' key");
}
// Fix ordering and remove unknown keys
$value = array(
'type' => strval($value['type']),
'value' => strval($value['value']),
'lang' => isset($value['lang']) ? strval($value['lang']) : null,
'datatype' => isset($value['datatype']) ? strval($value['datatype']) : null,
);
}
else {
$value = array(
'type' => 'literal',
'value' => strval($value),
'datatype' => EasyRdf_Literal::getDatatypeForValue($value),
);
}
if (!in_array($value['type'], array(
'uri',
'bnode',
'literal',
), true)) {
throw new InvalidArgumentException("\$value does not have a valid type (" . $value['type'] . ")");
}
if (empty($value['datatype'])) {
unset($value['datatype']);
}
if (empty($value['lang'])) {
unset($value['lang']);
}
if (isset($value['lang']) and isset($value['datatype'])) {
throw new InvalidArgumentException("\$value cannot have both and language and a datatype");
}
}
}