123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- class TripalWebService {
-
-
-
-
-
-
-
-
- public static $label = 'Base WebService';
-
- public static $description = 'This is the base class for Tripal web services as is not meant to be used on it\'s own';
-
- public static $type = 'services';
-
-
-
-
- protected $resource;
-
- protected $path;
-
- protected $params;
-
- protected $base_path;
-
-
-
-
- public function __construct($base_path) {
- if (!$base_path) {
- throw new Exception('Please provide a $base_path argument when creating a new TripalWebService.');
- }
-
- $this->resource = new TripalWebServiceResource($base_path);
-
- $this->path = array();
- $this->params = array();
- $this->base_path = $base_path;
- }
-
-
-
-
- public function handleRequest() {
-
-
- }
-
-
-
-
- public function setPath($path) {
- $this->path = $path;
- }
-
- public function setParams($params) {
- $this->params = $params;
- }
-
- public function getVersion($sanatize = FALSE) {
- $class = get_class($this);
- $major_version = '';
- $minor_version = '';
- if (preg_match('/v(\d+)_(\d+)$/', $class, $matches)) {
- $major_version = $matches[1];
- $minor_version = $matches[2];
- return 'v' . $major_version . '.' . $minor_version;
- }
- return '';
- }
-
- public function getContext() {
- return $this->resource->getContext();
- }
-
- public function getResponse() {
- $context = $this->resource ? $this->resource->getContext() : array();
- $type = $this->resource ? $this->resource->getType() : 'unknown';
- $json_ld = array(
- '@context' => $context,
- '@id' => '',
- '@type' => $type,
- );
- $data = $this->getData();
- return array_merge($json_ld, $data);
- }
-
- public function getServicePath() {
- $class = get_class($this);
- $version = $this->getVersion();
- $type = $class::$type;
- return $this->base_path . '/' . $type . '/' . $version;
- }
-
- public function getData() {
- if ($this->resource) {
- return $this->resource->getData();
- }
- return array();
- }
-
- public function setResource($resource) {
-
- if (!is_a($resource, 'TripalWebServiceResource')) {
- throw new Exception("Cannot add a new resource to this web service as it is not a TripalWebServiceResource.");
- }
- $this->resource = $resource;
- }
-
- public function setError($message) {
- $this->resource = new TripalWebServiceResource($this->base_path);
- $this->resource->setID('error');
- $this->resource->addContextItem('error', 'rdfs:error');
- $this->resource->addProperty('error', $message);
- }
-
- public function getSupportedClasses() {
- $supported_classes = array();
- return $supported_classes;
- }
- }
|