Documentation

ServiceClient extends CustomClient
in package

Service client for Service

Table of Contents

$headers  : array<string|int, mixed>
Headers
$idempotencyKey  : string
Idempotence key
$url  : string
Server host
$login  : string
Last logged in user This is used for performance improvements in ServiceClient::loginAs method For optimisation purposes only! Do not use in the client code
$rewriteMode  : bool
Rewrite mode.
$service  : string
Service name
$sessionId  : string
Session id
$traitDeleteAsPost  : bool
Trait DELETE requests as POST
$traitPutAsPost  : bool
Trait PUT requests as POST
__construct()  : mixed
Constructor
connect()  : void
Method connects to the REST server via login and password pair
getHeaders()  : array<string|int, mixed>
Method returns headers
getIdempotencyKey()  : string
Method returns idempotency key
getRewriteMode()  : bool
Getting rewrite mode for URLs
getSelfId()  : string
Method returns self id of the session
getSelfLogin()  : string
Method returns self login of the session
getService()  : string
Method returns service
getStoredLogin()  : string
Method returns stored login
getToken()  : string
Method returns token
getUrl()  : string
Method returns URL
loginAs()  : void
Method logins under another user $field must be 'id' or 'login'
sendDeleteRequest()  : mixed
Method sends DELETE request to server
sendGetRequest()  : mixed
Method sends GET request to server.
sendPostRequest()  : mixed
Method sends POST request to server
sendPutRequest()  : mixed
Method sends PUT request to server
setDeleteTraitMethod()  : void
Method traits DELETE as POST
setIdempotencyKey()  : void
Method sets idempotence key.
setPutTraitMethod()  : void
Method traits PUT as POST
setRewriteMode()  : void
Setting rewrite mode for URLs
setToken()  : void
Method sets token
setUrl()  : void
Method sets URL
dispatchResult()  : mixed
Method gets result and validates it.
getCommonHeaders()  : array<string|int, mixed>
Method returns common headers
getFormHeaders()  : array<string|int, mixed>
Method compiles post headers
getRequestUrl()  : string
Method returns concrete url byit's locator
sendFormRequest()  : mixed
Method sends request on server
sendRequest()  : array<string|int, mixed>
Method send request to the URL
validateSessionId()  : void
Method validates result
assertUrl()  : void
Method asserts that $url is set

Properties

$headers

Headers

protected array<string|int, mixed> $headers = []

$idempotencyKey

Idempotence key

protected string $idempotencyKey = ''

$login

Last logged in user This is used for performance improvements in ServiceClient::loginAs method For optimisation purposes only! Do not use in the client code

private string $login = ''

$rewriteMode

Rewrite mode.

private bool $rewriteMode = true

If true, then URLs like this /part1/part2/param1/ will be used. If false, then parameter ?r=part1/part2/param1 will be passed

$traitDeleteAsPost

Trait DELETE requests as POST

private bool $traitDeleteAsPost = false

$traitPutAsPost

Trait PUT requests as POST

private bool $traitPutAsPost = false

Methods

__construct()

Constructor

public __construct(string $service[, string $login = '' ][, string $password = '' ][, array<string|int, mixed> $headers = [] ]) : mixed
Parameters
$service : string

Service URL or service name

$login : string = ''

Login

$password : string = ''

Password

$headers : array<string|int, mixed> = []

Headers

Return values
mixed

connect()

Method connects to the REST server via login and password pair

public connect(string $login, string $password) : void
Parameters
$login : string

Login

$password : string

Password

Return values
void

getHeaders()

Method returns headers

public getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

Headers

getIdempotencyKey()

Method returns idempotency key

public getIdempotencyKey() : string
Return values
string

Idempotency key

getRewriteMode()

Getting rewrite mode for URLs

public getRewriteMode() : bool
Return values
bool

rewrite mode

getSelfId()

Method returns self id of the session

public getSelfId() : string
Return values
string

Session user's id

getSelfLogin()

Method returns self login of the session

public getSelfLogin() : string
Return values
string

Session user's login

getService()

Method returns service

public getService() : string
Return values
string

service

getStoredLogin()

Method returns stored login

public getStoredLogin() : string
Return values
string

Stored login

getToken()

Method returns token

public getToken() : string
Return values
string

Session id

getUrl()

Method returns URL

public getUrl() : string
Return values
string

URL

loginAs()

Method logins under another user $field must be 'id' or 'login'

public loginAs(string $user[, string $field = 'id' ]) : void
Parameters
$user : string

User credentials

$field : string = 'id'

Field name for credentials

Return values
void

sendDeleteRequest()

Method sends DELETE request to server

public sendDeleteRequest(string $endpoint[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
$endpoint : string

Calling endpoint

$data : array<string|int, mixed> = []

Request data

Return values
mixed

Result of the request

sendGetRequest()

Method sends GET request to server.

public sendGetRequest(string $endpoint) : mixed
Parameters
$endpoint : string

Calling endpoint.

Return values
mixed

Result of the remote call.

sendPostRequest()

Method sends POST request to server

public sendPostRequest(string $endpoint[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
$endpoint : string

Calling endpoint

$data : array<string|int, mixed> = []

Request data

Return values
mixed

Result of the request

sendPutRequest()

Method sends PUT request to server

public sendPutRequest(string $endpoint[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
$endpoint : string

Calling endpoint

$data : array<string|int, mixed> = []

Request data

Return values
mixed

Result of the request

setDeleteTraitMethod()

Method traits DELETE as POST

public setDeleteTraitMethod(bool $flag) : void
Parameters
$flag : bool
Return values
void

setIdempotencyKey()

Method sets idempotence key.

public setIdempotencyKey(string $key) : void

To remove the key just call this method the second time with the '' parameter

Parameters
$key : string

Idempotence key

Return values
void

setPutTraitMethod()

Method traits PUT as POST

public setPutTraitMethod(bool $flag) : void
Parameters
$flag : bool
Return values
void

setRewriteMode()

Setting rewrite mode for URLs

public setRewriteMode(bool $rewriteMode) : void
Parameters
$rewriteMode : bool

rewrite mode

Return values
void

setToken()

Method sets token

public setToken(string $token[, string $login = '' ]) : void
Parameters
$token : string

Access token

$login : string = ''

User login

Return values
void

setUrl()

Method sets URL

public setUrl(string $url) : void
Parameters
$url : string

URL

Return values
void

dispatchResult()

Method gets result and validates it.

protected dispatchResult(string $url, int $code, mixed $body) : mixed
Parameters
$url : string

request URL

$code : int

response HTTP code

$body : mixed

response body

Tags
see

CustomClient::dispatchResult(string $url, int $code, $body)

Return values
mixed

Request result

getCommonHeaders()

Method returns common headers

protected getCommonHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

Headers

getFormHeaders()

Method compiles post headers

protected getFormHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

Header

getRequestUrl()

Method returns concrete url byit's locator

protected getRequestUrl(string $urlLocator) : string
Parameters
$urlLocator : string

url locator

Return values
string

concrete URL

sendFormRequest()

Method sends request on server

protected sendFormRequest(string $method, string $endpoint[, mixed $data = [] ]) : mixed
Parameters
$method : string

HTTP method (POST|PUT|DELETE)

$endpoint : string

Calling endpoint

$data : mixed = []

Request data @return mixed request result

Return values
mixed

sendRequest()

Method send request to the URL

protected sendRequest(string $url, array<string|int, mixed> $headers, string $method[, array<string|int, mixed> $data = [] ]) : array<string|int, mixed>
Parameters
$url : string

URL

$headers : array<string|int, mixed>

Headers

$method : string

Request HTTP Method

$data : array<string|int, mixed> = []

Request data

Tags
codeCoverageIgnore
Return values
array<string|int, mixed>

Response body and HTTP code

validateSessionId()

Method validates result

protected validateSessionId(object $result) : void
Parameters
$result : object
Return values
void

assertUrl()

Method asserts that $url is set

private assertUrl() : void
Return values
void

Search results