private function TripalWebService::generateDocClassOp
3.x TripalWebService.inc | private TripalWebService::generateDocClassOp($supported_class, $op, $op_details) |
A helper function for the addClass() function for generating an operation.
1 call to TripalWebService::generateDocClassOp()
- TripalWebService::addDocClass in tripal_ws/
includes/ TripalWebService.inc - Defines an entity class for the web services.
File
- tripal_ws/
includes/ TripalWebService.inc, line 512
Class
Code
private function generateDocClassOp($supported_class, $op, $op_details) {
if ($op != 'GET' and $op != 'PUT' and $op != 'DELETE' and $op != 'POST') {
throw new Exception(t('The method, @method, provided to the TripalWebService::addClass function is not an oppropriate operations.', array('@method' => $op)));
}
if (!array_key_exists('type', $op_details)) {
throw new Exception(t('Please provide a type in the operations array passed to the TripalWebService::addClass() function: @details', array('@details' => print_r($op_details, TRUE))));
}
if (!array_key_exists('label', $op_details)) {
throw new Exception(t('Please provide a label in the operations array passed to the TripalWebService::addClass() function: @details', array('@details' => print_r($op_details, TRUE))));
}
$class_op = new TripalWebServiceResource($this->base_path);
$class_op->setID($op_details['type']);
switch ($op) {
case 'GET':
$class_op->setType('hydra:Operation');
break;
case 'POST':
$class_op->setType('http://schema.org/AddAction');
break;
case 'DELETE':
$class_op->setType('http://schema.org/DeleteAction');
break;
case 'PUT':
$class_op->setType('http://schema.org/UpdateAction');
break;
}
$class_op->addContextItem('method', 'hydra:method');
$class_op->addContextItem('label', 'rdfs:label');
$class_op->addContextItem('description', 'rdfs:comment');
$class_op->addContextItem('expects', array(
"@id" => "hydra:expects",
"@type" => "@id"
));
$class_op->addContextItem('returns', array(
"@id" => "hydra:returns",
"@type" => "@id"
));
$class_op->addContextItem('statusCodes', 'hydra:statusCodes');
$class_op->addContextItem('code', 'hydra:statusCode');
$class_op->addProperty('method', $op);
$class_op->addProperty('label', array_key_exists('label', $op_details) ? $op_details['label'] : 'Retrieves an instance of this resource');
$class_op->addProperty('description', array_key_exists('description', $op_details) ? $op_details['description'] : NULL);
$status_codes = array_key_exists('statusCodes', $op_details) ? $op_details['statusCodes'] : array();
foreach ($status_codes as $code) {
if (array_key_exists('code', $code) and array_key_exists('description', $code)) {
$class_op->addProperty('statusCodes', $code);
}
else {
throw new Exception(t('The status code provided to TripalWebService::addClass function is improperly formatted @code.', array('@code' => print_r($code, TRUE))));
}
}
if (count($status_codes) == 0) {
$class_op->addProperty('statusCodes', array());
}
$class_op->addProperty('expects', array_key_exists('expects', $op_details) ? $op_details['expects'] : NULL);
$class_op->addProperty('returns', array_key_exists('returns', $op_details) ? $op_details['returns'] : ' "http://www.w3.org/2002/07/owl#Nothing",');
return $class_op;
}