Contentserv PHP API

CSRest
in package

The starting point of the REST API

This API is accessable after a call to the CS::loadApi('CSRest');

Tags
access

public

since

CS13.0

Table of Contents

ERROR_REST_SERVICE_DISABLED  = 'REST_ERROR_SERVICE_DISABLED'
ERROR_REST_SERVICE_NO_CONTENT  = 'REST_ERROR_SERVICE_NO_CONTENT'
ERROR_REST_SERVICE_PLUGIN_AUTHORIZATION_REQUIRED  = 'REST_ERROR_SERVICE_PLUGIN_AUTHORIZATION_REQUIRED'
ERROR_REST_SERVICE_PLUGIN_DOCUMENTATION_NOT_AVAILABLE  = 'REST_ERROR_SERVICE_PLUGIN_DOCUMENTATION_NOT_AVAILABLE'
ERROR_REST_SERVICE_PLUGIN_HTTPS_REQUIRED  = 'REST_ERROR_SERVICE_PLUGIN_HTTPS_REQUIRED'
ERROR_REST_SERVICE_PLUGIN_IP_NOT_ACCEPTED  = 'REST_ERROR_SERVICE_PLUGIN_IP_NOT_ACCEPTED'
ERROR_REST_SERVICE_PLUGIN_NOT_ALLOWED  = 'REST_ERROR_SERVICE_PLUGIN_NOT_ALLOWED'
ERROR_REST_SERVICE_PLUGIN_NOT_FOUND  = 'REST_ERROR_SERVICE_PLUGIN_NOT_FOUND'
ERROR_REST_SERVICE_PLUGIN_NOT_IMPLEMENTED  = 'REST_ERROR_SERVICE_PLUGIN_NOT_IMPLEMENTED'
ERROR_REST_SERVICE_PLUGIN_NOT_LICENSED  = 'REST_ERROR_SERVICE_PLUGIN_NOT_LICENSED'
ERROR_REST_SERVICE_PLUGIN_NOT_SET_AVAILABLE  = 'REST_ERROR_SERVICE_PLUGIN_NOT_SET_AVAILABLE'
ERROR_REST_SERVICE_PLUGIN_USER_NOT_ACCEPTED  = 'REST_ERROR_SERVICE_PLUGIN_USER_NOT_ACCEPTED'
HTTP_CONTENT_TYPE_ATOM  = 'application/atom+xml;type=entry; charset=utf-8'
HTTP_CONTENT_TYPE_DEBUG  = 'text; charset=utf-8'
HTTP_CONTENT_TYPE_FOP  = 'application/pdf; charset=utf-8'
HTTP_CONTENT_TYPE_HTML  = 'text/html; charset=utf-8'
HTTP_CONTENT_TYPE_JSON  = 'application/json; charset=utf-8'
HTTP_CONTENT_TYPE_RSS  = 'application/rss+xml; charset=utf-8'
HTTP_CONTENT_TYPE_STREAM  = 'application/octet-stream'
HTTP_CONTENT_TYPE_XML  = 'text/xml; charset=utf-8'
HTTP_FORMAT_TYPE_ATOM  = 'atom'
HTTP_FORMAT_TYPE_DEBUG  = 'debug'
HTTP_FORMAT_TYPE_FOP  = 'fop'
HTTP_FORMAT_TYPE_HTML  = 'html'
HTTP_FORMAT_TYPE_JSON  = 'json'
HTTP_FORMAT_TYPE_RSS  = 'rss'
HTTP_FORMAT_TYPE_XML  = 'xml'
HTTP_PUT_CONTENT_IN_POST_VAR  = 'PUT_DATA'
HTTP_REQUEST_METHOD_DELETE  = 'DELETE'
HTTP_REQUEST_METHOD_GET  = 'GET'
HTTP_REQUEST_METHOD_POST  = 'POST'
HTTP_REQUEST_METHOD_PUT  = 'PUT'
HTTP_STATUS_CODE_200_OK  = 200
HTTP_STATUS_CODE_201_CREATED  = 201
HTTP_STATUS_CODE_204_NO_CONTENT  = 204
HTTP_STATUS_CODE_400_BAD_REQUEST  = 400
HTTP_STATUS_CODE_401_UNAUTHORIZED  = 401
HTTP_STATUS_CODE_403_FORBIDDEN  = 403
HTTP_STATUS_CODE_404_NOT_FOUND  = 404
HTTP_STATUS_CODE_405_METHOD_NOT_ALLOWED  = 405
HTTP_STATUS_CODE_423_LOCKED  = 423
HTTP_STATUS_CODE_497_HTTPS_REQUIRED  = 497
HTTP_STATUS_CODE_502_BAD_GATEWAY  = 502
SUCCESS_REST_SERVICE_CREATED_BUT_DISABLED  = 'REST_SUCCESS_SERVICE_CREATED_BUT_DISABLED'
$REST_SERVICE_CATEGORY_RIGHTS  : array<string|int, mixed>
Variable that stores the different rest categories, and it's different right names.
callService()  : string|object
Calls the Restservice through a simulated HTTP Request from the Server to itself
convertToHtml()  : string
A mixed data can be converted to a HTML with this method
convertToXML()  : string
A mixed data can be converted to XML with this method
createDefaultRestserviceForPlugin()  : CSRestservice
Creates a default REST service for the chosen plugin called via the REST service URL.
createRequest()  : mixed
createRestservice()  : CSRestservice
Creates a default REST service and stores it in the database.
fop()  : string
Renders a xsl:fo file to pdf using the FOP Apache renderer
formatOutput()  : string
An mixed data can be converted to HTML, XML, FOP, DEBUG or JSON based on the content type set.
getAvailableServiceTypesLabels()  : array<string|int, mixed>
Fetches the list of labels of the available service types
getCallingUserID()  : int
Returns the id of the user that was initially executing the rest request. This is important if a rest endpoint is configured to be executed as another user.
getCategories()  : array<string|int, mixed>
Gets the list of various categories that are set in the REST service.
getContentTypeForFormat()  : string
Gets the Content type for the format required.
getDefaultServiceKey()  : string
Gets the autogenerated 4-letter service key to be set for a new REST service.
getErrorMessage()  : string
Translates the error message.
getFormatForContentType()  : string
Gets the format of Content type required.
getRestservice()  : CSRestservice
Gets the REST service for a particular ID.
getRestserviceByKey()  : CSRestservice
Gets the REST service for a particular Service Key.
getRestservices()  : array<string|int, CSRestservice>
Returns all REST services available for a user
getSupportedOutputFormats()  : array<string|int, mixed>
Returns all valid outputs formats currently supported by the rest framework.
handleRequest()  : mixed
hasRestserviceRights()  : bool
Method that returns true whenever any of the restservice category rights is present, or false otherwise.
isAvailableForServiceType()  : bool
Returns if the current user has access to the specified service type.
logRequest()  : int
Adds a Log entry when a REST services is requested.
logResponse()  : void
Updates an existing Log entry when the REST service is responded.
transformXml()  : string
Transforms an xml output with a style sheet

Constants

ERROR_REST_SERVICE_DISABLED

public mixed ERROR_REST_SERVICE_DISABLED = 'REST_ERROR_SERVICE_DISABLED'
Tags

ERROR_REST_SERVICE_NO_CONTENT

public mixed ERROR_REST_SERVICE_NO_CONTENT = 'REST_ERROR_SERVICE_NO_CONTENT'
Tags

ERROR_REST_SERVICE_PLUGIN_AUTHORIZATION_REQUIRED

public mixed ERROR_REST_SERVICE_PLUGIN_AUTHORIZATION_REQUIRED = 'REST_ERROR_SERVICE_PLUGIN_AUTHORIZATION_REQUIRED'
Tags

ERROR_REST_SERVICE_PLUGIN_DOCUMENTATION_NOT_AVAILABLE

public mixed ERROR_REST_SERVICE_PLUGIN_DOCUMENTATION_NOT_AVAILABLE = 'REST_ERROR_SERVICE_PLUGIN_DOCUMENTATION_NOT_AVAILABLE'
Tags

ERROR_REST_SERVICE_PLUGIN_HTTPS_REQUIRED

public mixed ERROR_REST_SERVICE_PLUGIN_HTTPS_REQUIRED = 'REST_ERROR_SERVICE_PLUGIN_HTTPS_REQUIRED'
Tags

ERROR_REST_SERVICE_PLUGIN_IP_NOT_ACCEPTED

public mixed ERROR_REST_SERVICE_PLUGIN_IP_NOT_ACCEPTED = 'REST_ERROR_SERVICE_PLUGIN_IP_NOT_ACCEPTED'
Tags

ERROR_REST_SERVICE_PLUGIN_NOT_ALLOWED

public mixed ERROR_REST_SERVICE_PLUGIN_NOT_ALLOWED = 'REST_ERROR_SERVICE_PLUGIN_NOT_ALLOWED'
Tags

ERROR_REST_SERVICE_PLUGIN_NOT_FOUND

public mixed ERROR_REST_SERVICE_PLUGIN_NOT_FOUND = 'REST_ERROR_SERVICE_PLUGIN_NOT_FOUND'
Tags

ERROR_REST_SERVICE_PLUGIN_NOT_IMPLEMENTED

public mixed ERROR_REST_SERVICE_PLUGIN_NOT_IMPLEMENTED = 'REST_ERROR_SERVICE_PLUGIN_NOT_IMPLEMENTED'
Tags

ERROR_REST_SERVICE_PLUGIN_NOT_LICENSED

public mixed ERROR_REST_SERVICE_PLUGIN_NOT_LICENSED = 'REST_ERROR_SERVICE_PLUGIN_NOT_LICENSED'
Tags

ERROR_REST_SERVICE_PLUGIN_NOT_SET_AVAILABLE

public mixed ERROR_REST_SERVICE_PLUGIN_NOT_SET_AVAILABLE = 'REST_ERROR_SERVICE_PLUGIN_NOT_SET_AVAILABLE'
Tags

ERROR_REST_SERVICE_PLUGIN_USER_NOT_ACCEPTED

public mixed ERROR_REST_SERVICE_PLUGIN_USER_NOT_ACCEPTED = 'REST_ERROR_SERVICE_PLUGIN_USER_NOT_ACCEPTED'
Tags

HTTP_CONTENT_TYPE_ATOM

public mixed HTTP_CONTENT_TYPE_ATOM = 'application/atom+xml;type=entry; charset=utf-8'
Tags

HTTP_CONTENT_TYPE_DEBUG

public mixed HTTP_CONTENT_TYPE_DEBUG = 'text; charset=utf-8'
Tags

HTTP_CONTENT_TYPE_FOP

public mixed HTTP_CONTENT_TYPE_FOP = 'application/pdf; charset=utf-8'
Tags

HTTP_CONTENT_TYPE_HTML

public mixed HTTP_CONTENT_TYPE_HTML = 'text/html; charset=utf-8'
Tags

HTTP_CONTENT_TYPE_JSON

public mixed HTTP_CONTENT_TYPE_JSON = 'application/json; charset=utf-8'
Tags

HTTP_CONTENT_TYPE_RSS

public mixed HTTP_CONTENT_TYPE_RSS = 'application/rss+xml; charset=utf-8'
Tags

HTTP_CONTENT_TYPE_STREAM

public mixed HTTP_CONTENT_TYPE_STREAM = 'application/octet-stream'
Tags

HTTP_CONTENT_TYPE_XML

public mixed HTTP_CONTENT_TYPE_XML = 'text/xml; charset=utf-8'
Tags

HTTP_FORMAT_TYPE_ATOM

public mixed HTTP_FORMAT_TYPE_ATOM = 'atom'
Tags

HTTP_FORMAT_TYPE_DEBUG

public mixed HTTP_FORMAT_TYPE_DEBUG = 'debug'
Tags

HTTP_FORMAT_TYPE_FOP

public mixed HTTP_FORMAT_TYPE_FOP = 'fop'
Tags

HTTP_FORMAT_TYPE_HTML

public mixed HTTP_FORMAT_TYPE_HTML = 'html'
Tags

HTTP_FORMAT_TYPE_JSON

public mixed HTTP_FORMAT_TYPE_JSON = 'json'
Tags

HTTP_FORMAT_TYPE_RSS

public mixed HTTP_FORMAT_TYPE_RSS = 'rss'
Tags

HTTP_FORMAT_TYPE_XML

public mixed HTTP_FORMAT_TYPE_XML = 'xml'
Tags

HTTP_PUT_CONTENT_IN_POST_VAR

public mixed HTTP_PUT_CONTENT_IN_POST_VAR = 'PUT_DATA'
Tags

HTTP_REQUEST_METHOD_DELETE

public mixed HTTP_REQUEST_METHOD_DELETE = 'DELETE'
Tags

HTTP_REQUEST_METHOD_GET

public mixed HTTP_REQUEST_METHOD_GET = 'GET'
Tags

HTTP_REQUEST_METHOD_POST

public mixed HTTP_REQUEST_METHOD_POST = 'POST'
Tags

HTTP_REQUEST_METHOD_PUT

public mixed HTTP_REQUEST_METHOD_PUT = 'PUT'
Tags

HTTP_STATUS_CODE_200_OK

public mixed HTTP_STATUS_CODE_200_OK = 200
Tags

HTTP_STATUS_CODE_201_CREATED

public mixed HTTP_STATUS_CODE_201_CREATED = 201
Tags

HTTP_STATUS_CODE_204_NO_CONTENT

public mixed HTTP_STATUS_CODE_204_NO_CONTENT = 204
Tags

HTTP_STATUS_CODE_400_BAD_REQUEST

public mixed HTTP_STATUS_CODE_400_BAD_REQUEST = 400
Tags

HTTP_STATUS_CODE_401_UNAUTHORIZED

public mixed HTTP_STATUS_CODE_401_UNAUTHORIZED = 401
Tags

HTTP_STATUS_CODE_403_FORBIDDEN

public mixed HTTP_STATUS_CODE_403_FORBIDDEN = 403
Tags

HTTP_STATUS_CODE_404_NOT_FOUND

public mixed HTTP_STATUS_CODE_404_NOT_FOUND = 404
Tags

HTTP_STATUS_CODE_405_METHOD_NOT_ALLOWED

public mixed HTTP_STATUS_CODE_405_METHOD_NOT_ALLOWED = 405
Tags

HTTP_STATUS_CODE_423_LOCKED

public mixed HTTP_STATUS_CODE_423_LOCKED = 423
Tags

HTTP_STATUS_CODE_497_HTTPS_REQUIRED

public mixed HTTP_STATUS_CODE_497_HTTPS_REQUIRED = 497
Tags

HTTP_STATUS_CODE_502_BAD_GATEWAY

public mixed HTTP_STATUS_CODE_502_BAD_GATEWAY = 502
Tags

SUCCESS_REST_SERVICE_CREATED_BUT_DISABLED

public mixed SUCCESS_REST_SERVICE_CREATED_BUT_DISABLED = 'REST_SUCCESS_SERVICE_CREATED_BUT_DISABLED'
Tags

Properties

$REST_SERVICE_CATEGORY_RIGHTS

Variable that stores the different rest categories, and it's different right names.

public static array<string|int, mixed> $REST_SERVICE_CATEGORY_RIGHTS = array(\Restservice::TYPE_PUBLIC => 'public', \Restservice::TYPE_BUSINESS => 'business', \Restservice::TYPE_USER => 'user', \Restservice::TYPE_SYSTEM => 'system', \Restservice::TYPE_INTERNAL => 'internal')
Tags

Methods

callService()

Calls the Restservice through a simulated HTTP Request from the Server to itself

public static callService(string $serviceKeyOrID[, string $function = '' ][, array<string|int, mixed> $directories = array() ][, array<string|int, mixed> $get = array() ][, string $format = '' ][, string $anchor = '' ][, string $username = '' ][, string $method = 'GET' ][, string $body = '' ][, string $password = null ][, int $iTimeout = 120 ][, array<string|int, mixed>|null $aCookies = null ][, bool $bExtendedResult = false ]) : string|object
Parameters
$serviceKeyOrID : string

the name of the REST service

$function : string = ''

the first parameter after the service key, which is normally the base function

$directories : array<string|int, mixed> = array()

an array with further path parameters

$get : array<string|int, mixed> = array()

an associative array with GET key=>val parameters, that should be appended after the ? character

$format : string = ''

the format in which the webservice should deliver results, normally html, json, debug or xml

$anchor : string = ''

an optional anchor that should be appended after a hash (#)

$username : string = ''

the username of the user that should be used for authentication, if empty the webservice is called anonymously

$method : string = 'GET'

the HTTP method that should be used to call up he webservice, can be GET, POST, DELETE or PUT

$body : string = ''

the content of the HTTP body, possible together with POST or PUT methods

$password : string = null

the password used for authentication. IF left out or set to NULL the authentication will be done via CSPin generated on the Server. If provided the authentication will be done using the base64 encoded Authorization header

$iTimeout : int = 120

the timeout of the http request if set to a value larger than 0

$aCookies : array<string|int, mixed>|null = null

the array with the information regarding the cookies

$bExtendedResult : bool = false

if the response should be plain text or an actual response object

Tags
access

public

Return values
string|object

the resulting body of the HTTP response, or the response object

convertToHtml()

A mixed data can be converted to a HTML with this method

public static convertToHtml(mixed $data[, string $title = 'Data' ][, string $level = 1 ]) : string
Parameters
$data : mixed

the object, array or a simple string to be converted

$title : string = 'Data'

the caption of the table

$level : string = 1

used specifically for recursion, from outside one should not provide any value

Tags
access

public

Return values
string

$output Converted HTML as string

convertToXML()

A mixed data can be converted to XML with this method

public static convertToXML(array<string|int, mixed> $data[, string $tagName = 'Response' ][, bool $includePraeamble = TRUE ][, string $level = 1 ][, mixed $parentTagName = NULL ]) : string
Parameters
$data : array<string|int, mixed>

the object, array or a simple string to be converted

$tagName : string = 'Response'

the name of the element

$includePraeamble : bool = TRUE

to put the XML version tag or not

$level : string = 1

used specifically for recursion, from outside one should not provide any value

$parentTagName : mixed = NULL
Tags
access

public

Return values
string

Converted XML as string

createDefaultRestserviceForPlugin()

Creates a default REST service for the chosen plugin called via the REST service URL.

public static createDefaultRestserviceForPlugin(CSRestservicePlugin $plugin) : CSRestservice
Parameters
$plugin : CSRestservicePlugin

the REST service plugin object

Tags
access

public

Return values
CSRestservice

CSRestservice object

createRequest()

public static createRequest() : mixed
Tags
Return values
mixed

createRestservice()

Creates a default REST service and stores it in the database.

public static createRestservice() : CSRestservice
Tags
access

public

Return values
CSRestservice

CSRestservice object

fop()

Renders a xsl:fo file to pdf using the FOP Apache renderer

public static fop(mixed $xml[, string $format = 'pdf' ]) : string
Parameters
$xml : mixed
$format : string = 'pdf'

at the moment only pdf is supported

Tags
Return values
string

local file path of the generated pdf file

formatOutput()

An mixed data can be converted to HTML, XML, FOP, DEBUG or JSON based on the content type set.

public static formatOutput(mixed $data[, string $contentType = NULL ][, bool $title = '' ][, string $template = '' ]) : string
Parameters
$data : mixed

the object, array or a simple string to be converted

$contentType : string = NULL

the content type of the response

$title : bool = ''

in case of HTML, the title of the page

$template : string = ''

complete path to a template that should be used to render the output

Tags
access

public

Return values
string

Converted content as string

getAvailableServiceTypesLabels()

Fetches the list of labels of the available service types

public static getAvailableServiceTypesLabels() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

List of labels of the available service types

getCallingUserID()

Returns the id of the user that was initially executing the rest request. This is important if a rest endpoint is configured to be executed as another user.

public static getCallingUserID() : int
Tags
access

public

Return values
int

The id of the user that is executing the rest request.

getCategories()

Gets the list of various categories that are set in the REST service.

public static getCategories() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

of category strings

getContentTypeForFormat()

Gets the Content type for the format required.

public static getContentTypeForFormat(string $format) : string
Parameters
$format : string

eg. 'xml', 'fop', 'json', 'debug', 'atom' and 'html'

Tags
access

public

Return values
string

the content type

getDefaultServiceKey()

Gets the autogenerated 4-letter service key to be set for a new REST service.

public final static getDefaultServiceKey() : string
Tags
access

public

Return values
string

the new 4-letter service key

getErrorMessage()

Translates the error message.

public static getErrorMessage(string $type) : string
Parameters
$type : string

the key for translation

Tags
access

public

Return values
string

translated text

getFormatForContentType()

Gets the format of Content type required.

public static getFormatForContentType(mixed $contentType) : string
Parameters
$contentType : mixed
Tags
access

public

Return values
string

eg. 'xml', 'fop', 'json', 'debug' and 'html' or by default 'unknown'

getRestservice()

Gets the REST service for a particular ID.

public static getRestservice(int $ID) : CSRestservice
Parameters
$ID : int

the REST service ID

Tags
access

public

Return values
CSRestservice

CSRestservice object

getRestserviceByKey()

Gets the REST service for a particular Service Key.

public static getRestserviceByKey(string $key) : CSRestservice
Parameters
$key : string

the service key

Tags
access

public

Return values
CSRestservice

CSRestservice object or NULL if the service is not found

getRestservices()

Returns all REST services available for a user

public static getRestservices([int $UserID = NULL ][, string $filter = NULL ][, string $orderby = NULL ]) : array<string|int, CSRestservice>
Parameters
$UserID : int = NULL

optional UserID, if empty the current user will be taken

$filter : string = NULL

optional SQL filter against the Restservice table model

$orderby : string = NULL

optional SQL sort order against the Restservice table model

Tags
access

public

Return values
array<string|int, CSRestservice>

array of CSRestservice objects

getSupportedOutputFormats()

Returns all valid outputs formats currently supported by the rest framework.

public static getSupportedOutputFormats() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

list of supported output formats.

handleRequest()

public static handleRequest(CSRestserviceRequest $request) : mixed
Parameters
$request : CSRestserviceRequest
Tags
Return values
mixed

hasRestserviceRights()

Method that returns true whenever any of the restservice category rights is present, or false otherwise.

public static hasRestserviceRights() : bool
Tags
Return values
bool

isAvailableForServiceType()

Returns if the current user has access to the specified service type.

public static isAvailableForServiceType(int $iServiceType) : bool
Parameters
$iServiceType : int

The service type to check as one of the Restservice::TYPE_* constants

Tags
access

public

Return values
bool

True, if service type is available for current user, otherwise false.

logRequest()

Adds a Log entry when a REST services is requested.

public static logRequest(mixed $request) : int
Parameters
$request : mixed

the CSRestserviceRequest object

Tags
access

public

Return values
int

LogID of the new Log Entry

logResponse()

Updates an existing Log entry when the REST service is responded.

public static logResponse(int $LogID, CSRestserviceResponse $response) : void
Parameters
$LogID : int

the ID of the existing previous Log Entry for the request

$response : CSRestserviceResponse

the CSRestserviceResponse object

Tags
access

public

Return values
void

transformXml()

Transforms an xml output with a style sheet

public static transformXml(mixed $xml, mixed $template) : string
Parameters
$xml : mixed

the xml content as stream to transform

$template : mixed

the xsl file either as MAMFileID or xsl file name relative to the project

Tags
Return values
string

transformed xml content


        

Search results