Nextcloud PHP API (master)

OCSController extends ApiController
in package

AbstractYes

Base class to inherit your controllers from that are used for RESTful APIs

Tags
since
8.1.0

Table of Contents

Constants

RESPOND_NOT_FOUND  = 998
RESPOND_SERVER_ERROR  = 996
RESPOND_UNAUTHORISED  = 997
RESPOND_UNKNOWN_ERROR  = 999

Properties

$appName  : string
app name
$request  : IRequest
current request
$corsAllowedHeaders  : mixed
$corsMaxAge  : mixed
$corsMethods  : mixed
$ocsVersion  : int
$responders  : array<string|int, mixed>

Methods

__construct()  : mixed
constructor of the controller
buildResponse()  : Response
Since the OCS endpoints default to XML we need to find out the format again
getResponderByHTTPHeader()  : string
Parses an HTTP accept header and returns the supported responder type
preflightedCors()  : mixed
This method implements a preflighted cors response for you that you can link to for the options request
registerResponder()  : mixed
Registers a formatter for a type
buildOCSResponse()  : BaseResponse
Unwrap data and build ocs response

Constants

RESPOND_NOT_FOUND

public mixed RESPOND_NOT_FOUND = 998
Tags
since
22.0.0

RESPOND_SERVER_ERROR

public mixed RESPOND_SERVER_ERROR = 996
Tags
since
22.0.0

RESPOND_UNAUTHORISED

public mixed RESPOND_UNAUTHORISED = 997
Tags
since
22.0.0

RESPOND_UNKNOWN_ERROR

public mixed RESPOND_UNKNOWN_ERROR = 999
Tags
since
22.0.0

Properties

$appName

app name

protected string $appName
Tags
since
7.0.0

$responders

private array<string|int, mixed> $responders
Tags
since
7.0.0

Methods

__construct()

constructor of the controller

public __construct(string $appName, IRequest $request[, string $corsMethods = 'PUT, POST, GET, DELETE, PATCH' ][, string $corsAllowedHeaders = 'Authorization, Content-Type, Accept, OCS-APIRequest' ][, int $corsMaxAge = 1728000 ]) : mixed
Parameters
$appName : string

the name of the app

$request : IRequest

an instance of the request

$corsMethods : string = 'PUT, POST, GET, DELETE, PATCH'

comma separated string of HTTP verbs which should be allowed for websites or webapps when calling your API, defaults to 'PUT, POST, GET, DELETE, PATCH'

$corsAllowedHeaders : string = 'Authorization, Content-Type, Accept, OCS-APIRequest'

comma separated string of HTTP headers which should be allowed for websites or webapps when calling your API, defaults to 'Authorization, Content-Type, Accept'

$corsMaxAge : int = 1728000

number in seconds how long a preflighted OPTIONS request should be cached, defaults to 1728000 seconds

Tags
since
8.1.0

buildResponse()

Since the OCS endpoints default to XML we need to find out the format again

public buildResponse(mixed $response[, string $format = 'xml' ]) : Response
Parameters
$response : mixed

the value that was returned from a controller and is not a Response instance

$format : string = 'xml'

the format for which a formatter has been registered

Tags
throws
DomainException

if format does not match a registered formatter

since
9.1.0
Return values
Response

getResponderByHTTPHeader()

Parses an HTTP accept header and returns the supported responder type

public getResponderByHTTPHeader(string $acceptHeader[, string $default = 'json' ]) : string
Parameters
$acceptHeader : string
$default : string = 'json'
Tags
since
7.0.0
since
9.1.0

Added default parameter

Return values
string

the responder type

preflightedCors()

This method implements a preflighted cors response for you that you can link to for the options request

public preflightedCors() : mixed
Tags
NoAdminRequired
NoCSRFRequired
PublicPage
since
7.0.0

registerResponder()

Registers a formatter for a type

protected registerResponder(string $format, Closure $responder) : mixed
Parameters
$format : string
$responder : Closure
Tags
since
7.0.0

buildOCSResponse()

Unwrap data and build ocs response

private buildOCSResponse(string $format, DataResponse $data) : BaseResponse
Parameters
$format : string

json or xml

$data : DataResponse

the data which should be transformed

Tags
since
8.1.0
Return values
BaseResponse

        
On this page

Search results