123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- class TripalDocService_v0_1 extends TripalWebService {
- /**
- * The human-readable label for this web service.
- */
- public static $label = 'API Documentation';
- /**
- * A bit of text to describe what this service provides.
- */
- public static $description = 'Provides Hydra style documenation to make this RESTful webservice discoverable.';
- /**
- * A machine-readable type for this service. This name must be unique
- * among all Tripal web services and is used to form the URL to access
- * this service.
- */
- public static $type = 'doc';
- /**
- * The list of web services.
- */
- private $services;
- /**
- * Constructor for the TripalDocService_v0_1 class.
- */
- public function __construct($base_path) {
- parent::__construct($base_path);
- // Get the list of services provided by this Tripal site.
- $this->services = tripal_get_web_services();
- foreach ($this->services as $sindex => $service_class) {
- // Load the class code.
- tripal_load_include_web_service_class($service_class);
- // Remove this class from the list of services.
- if ($service_class::$type == 'vocab') {
- unset($this->services[$sindex]);
- }
- }
- }
- /**
- * @see TripalWebService::handleRequest()
- */
- public function handleRequest() {
- // Create the vocabulary resource.
- $this->resource->addContextItem('vocab', $this->getServicePath() . '#');
- $this->resource->addContextItem('apiDocumentation', 'hydra:apiDocumentation');
- $this->resource->addContextItem('supportedClass', 'hydra:supportedClass');
- $this->resource->setType('apiDocumentation');
- $this->resource->setID('doc/' . $this->getVersion());
- // Add the EntryPoint class.
- $this->addEntryPointClass();
- foreach ($this->documentation as $supported) {
- $this->resource->addProperty('supportedClass', $supported);
- }
- // Iterate through all of the web services and build their documentation
- foreach ($this->services as $service_class) {
- $service = new $service_class($this->base_path);
- $supported_classes = $service->getDocumentation();
- foreach ($supported_classes as $supported) {
- $this->resource->addProperty('supportedClass', $supported);
- }
- }
- }
- /**
- * Generates the EntryPoint class for the API documents.
- *
- * @return TripalWebServiceResource
- *
- */
- private function addEntryPointClass(){
- $service_path = $this->getServicePath();
- $details = array(
- 'id' => $service_path . '#EntryPoint',
- 'term' => 'vocab:EntryPoint',
- 'title' => 'EntryPoint',
- 'description' => 'The main entry point or homepage of the API',
- 'subClassOf' => NULL,
- );
- // Add each service as a property.
- $properties = array();
- foreach ($this->services as $service_class) {
- $service = new $service_class($this->base_path);
- // Create a WebServiceResource for the hydra:Link type.
- $link = new TripalWebServiceResource($this->base_path);
- $link->setID('vocab:EntryPoint/' . $service::$type);
- $link->setType('hydra:Link');
- $link->addContextItem('domain', array(
- "@id" => "rdfs:domain",
- "@type" => "@id"
- ));
- $link->addContextItem('range', array(
- "@id" => "rdfs:range",
- "@type" => "@id"
- ));
- $link->addContextItem('readable', 'hydra:readable');
- $link->addContextItem('writeable', 'hydra:writeable');
- $link->addContextItem('required', 'hydra:required');
- $link->addContextItem('description', 'rdfs:comment');
- $link->addContextItem('label', 'rdfs:label');
- $link->addProperty('hydra:title', $service_class::$label);
- $link->addProperty('hydra:description', $service_class::$description);
- // $link->addProperty('domain', $service_path . '#EntryPoint');
- // $link->addProperty('range', $service_class::$label);
- $ops = array();
- $op = new TripalWebServiceResource($this->base_path);
- $op->setID('_:' . $service::$type . '_retrieve');
- $op->setType('hydra:Operation');
- $op->addContextItem('method', 'hydra:method');
- $op->addContextItem('label', 'rdfs:label');
- $op->addContextItem('description', 'rdfs:comment');
- $op->addContextItem('expects', array(
- "@id" => "hydra:expects",
- "@type" => "@id"
- ));
- $op->addContextItem('returns', array(
- "@id" => "hydra:returns",
- "@type" => "@id"
- ));
- $op->addContextItem('statusCodes', 'hydra:statusCodes');
- $op->addProperty('method', "GET");
- $op->addProperty('label', 'Retrieves the ' . $service_class::$label . ' resource.');
- $op->addProperty('description', NULL);
- $op->addProperty('expects', NULL);
- $op->addProperty('returns', 'local:EntryPoint/' . $service::$type);
- $op->addProperty('statusCodes', array());
- $ops[] = $op;
- $link->addContextItem('supportedOperation', 'hydra:supportedOperation');
- $link->addProperty('supportedOperation', $ops);
- $property = array(
- 'type' => $link,
- 'title' => $service_class::$label,
- 'description' => $service_class::$description,
- 'domain', 'vocab:EntryPoint',
- 'range', $service->getServicePath(),
- );
- $properties[] = $property;
- }
- $operations = array();
- $operations['GET'] = array(
- 'label' => "The APIs main entry point.",
- 'description' => NULL,
- 'expects' => NULL,
- 'returns' => $service_path . '#EntryPoint',
- 'type' => '_:entry_point_retrieve'
- );
- $this->addDocClass($details, $operations, $properties);
- }
- }
|