private function TripalWebServiceResource::checkKey
3.x TripalWebServiceResource.inc | private TripalWebServiceResource::checkKey($key) |
Checks a key to ensure it is in the Context before being used.
This function should be used before adding a property or type to this resource. It ensures that the key for the property is already in the context.
Parameters
$key: The key to check.
Throws
Exception
3 calls to TripalWebServiceResource::checkKey()
- TripalWebServiceResource::addProperty in tripal_ws/
includes/ TripalWebServiceResource.inc - Adds a new key/value pair to the web serivces response.
- TripalWebServiceResource::checkValue in tripal_ws/
includes/ TripalWebServiceResource.inc - Checks the value to make sure there are no problems with.
- TripalWebServiceResource::setType in tripal_ws/
includes/ TripalWebServiceResource.inc - Sets the resource type.
File
- tripal_ws/
includes/ TripalWebServiceResource.inc, line 129
Class
Code
private function checkKey($key) {
// Make sure the key is already present in the context.
$keys = array_keys($this->context);
// Keys that are full HTML are acceptable
if (preg_match('/^(http|https):\/\/.*/', $key)) {
return;
}
// If the key has a colon separating the vocabulary and the term then we
// just need to make sure that the vocabulary is present.
$matches = array();
if (preg_match('/^(.*?):(.*?)$/', $key, $matches)) {
$vocab = $matches[1];
$accession = $matches[2];
// The underscore represents the blank node. So, these keys are okay.
if ($vocab == '_') {
return;
}
// If the vocabulary is not in the.
if (!in_array($vocab, $keys)) {
throw new Exception(t("The key, !key, has a vocabulary that has not yet been added to the " .
"context. Use the addContextItem() function to add the vocabulary prior to adding a value for it.", array('!key' => $key)));
}
}
else {
// If the key is not in the context then throw an error.
if (!in_array($key, $keys)) {
throw new Exception(t("The key, !key, has not yet been added to the " .
"context. Use the addContextItem() function to add this key prior to adding a value for it.", array('!key' => $key)));
}
}
}