Documentation

CrudServiceClient extends ServiceClient
in package
implements CrudServiceClientInterface

Class for basic Crud API client.

Tags
author

Dodonov A.A.

Interfaces, Classes and Traits

CrudServiceClientInterface
Interface for basic Crud API client

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
create()  : int
Method creates new record
delete()  : string
Method deletes record with $id
deleteFiltered()  : mixed
Method deletes records by filter
getById()  : object
Method returns record by it's id
getByIdsArray()  : array<string|int, mixed>
Method returns records by their ids
getFields()  : array<string|int, mixed>
Method returns fields and layout
getHeaders()  : array<string|int, mixed>
Method returns headers
getIdempotencyKey()  : string
Method returns idempotency key
getList()  : array<string|int, mixed>
Method returns some records of the user's domain
getRecordsBy()  : array<string|int, mixed>
Method returns all records by filter
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
instance()  : CrudServiceClient
Method creates instance if the CrudServiceClient class
lastRecords()  : array<string|int, mixed>
Method returns last $count records
loginAs()  : void
Method logins under another user $field must be 'id' or 'login'
newRecordsSince()  : array<string|int, mixed>
Method returns all records created since $date
recordsCount()  : array<string|int, mixed>
Method returns count of records
recordsCountByField()  : array<string|int, mixed>
Method returns count off records
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
update()  : mixed
Method updates new record
createFileField()  : array<string|int, mixed>
Method compiles file field
dispatchResult()  : mixed
Method gets result and validates it.
getCommonHeaders()  : array<string|int, mixed>
Method returns common headers
getCompiledFilter()  : string
Method returns compiled filter string
getCompiledOrder()  : string
Method compiles sorting settings
getFormHeaders()  : array<string|int, mixed>
Method compiles post headers
getRequestUrl()  : string
Method returns concrete url byit's locator
isFile()  : bool
Checking if we are uploading a file
pretransformData()  : string
Transforming data before sending to service
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 $url = '' ][, array<string|int, mixed> $headers = [] ]) : mixed
Parameters
$url : string = ''

service URL

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

HTTP 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

create()

Method creates new record

public create(array<string|int, mixed> $data) : int
Parameters
$data : array<string|int, mixed>

data for creating record

Return values
int

id of the created record

delete()

Method deletes record with $id

public delete(int $id, int $crossDomain) : string
Parameters
$id : int

Id of the deleting record

$crossDomain : int

Break domain's bounds or not

Tags
codeCoverageIgnore
Return values
string

Result of the deletion

deleteFiltered()

Method deletes records by filter

public deleteFiltered(int $crossDomain[, array<string|int, mixed> $filter = false ]) : mixed
Parameters
$crossDomain : int

Cross domain security settings

$filter : array<string|int, mixed> = false

Filtering settings

Tags
codeCoverageIgnore
Return values
mixed

getById()

Method returns record by it's id

public getById(int $id, number $crossDomain) : object
Parameters
$id : int

Id of the fetching record

$crossDomain : number

Domain id

Tags
codeCoverageIgnore
Return values
object

fetched record

getByIdsArray()

Method returns records by their ids

public getByIdsArray(array<string|int, mixed> $ids, number $crossDomain) : array<string|int, mixed>
Parameters
$ids : array<string|int, mixed>

List of ids

$crossDomain : number

Domain id

Return values
array<string|int, mixed>

Fetched records

getFields()

Method returns fields and layout

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

Fields and layout

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

getList()

Method returns some records of the user's domain

public getList(int $from[, int $limit = 1000000000 ], int $crossDomain[, array<string|int, mixed> $filter = false ][, array<string|int, mixed> $order = false ]) : array<string|int, mixed>
Parameters
$from : int

The beginnig of the fetching sequence

$limit : int = 1000000000

Size of the fetching sequence

$crossDomain : int

Cross domain security settings

$filter : array<string|int, mixed> = false

Filtering settings

$order : array<string|int, mixed> = false

Sorting settings

Return values
array<string|int, mixed>

List of records

getRecordsBy()

Method returns all records by filter

public getRecordsBy(array<string|int, mixed> $filter, int $crossDomain) : array<string|int, mixed>
Parameters
$filter : array<string|int, mixed>

Filtering settings

$crossDomain : int

Cross domain security settings

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

List of records

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

instance()

Method creates instance if the CrudServiceClient class

public static instance(string $service, string $token) : CrudServiceClient
Parameters
$service : string

Service to be connected to

$token : string

Connection token

Return values
CrudServiceClient

Instance of the CrudServiceClient class

lastRecords()

Method returns last $count records

public lastRecords(int $count, array<string|int, mixed> $filter) : array<string|int, mixed>
Parameters
$count : int

Amount of records to be fetched

$filter : array<string|int, mixed>

Filter data

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

$count of last created records

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

newRecordsSince()

Method returns all records created since $date

public newRecordsSince(datetime $date) : array<string|int, mixed>
Parameters
$date : datetime

Start of the period

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

List of records created since $date

recordsCount()

Method returns count of records

public recordsCount() : array<string|int, mixed>
Tags
codeCoverageIgnore
Return values
array<string|int, mixed>

List of records created since $date

recordsCountByField()

Method returns count off records

public recordsCountByField(string $field[, array<string|int, mixed> $filter = false ]) : array<string|int, mixed>
Parameters
$field : string

Field for grouping

$filter : array<string|int, mixed> = false

Filtering settings

Return values
array<string|int, mixed>

List of records created since $date

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

update()

Method updates new record

public update(int $id, array<string|int, mixed> $data, int $crossDomain) : mixed
Parameters
$id : int

Id of the updating record

$data : array<string|int, mixed>

Data to be posted

$crossDomain : int

Cross domain policy

Tags
codeCoverageIgnore
Return values
mixed

Result of the RPC call

createFileField()

Method compiles file field

protected createFileField(string $path, string $name) : array<string|int, mixed>
Parameters
$path : string

Path to file

$name : string

Field name

Return values
array<string|int, mixed>

Field data

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

Return values
mixed

Request result

getCommonHeaders()

Method returns common headers

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

Headers

getCompiledFilter()

Method returns compiled filter string

protected getCompiledFilter(array<string|int, mixed> $filter[, bool $amp = true ]) : string
Parameters
$filter : array<string|int, mixed>

Filter

$amp : bool = true

Do we need &

Return values
string

Compiled filter

getCompiledOrder()

Method compiles sorting settings

protected getCompiledOrder(array<string|int, mixed> $order) : string
Parameters
$order : array<string|int, mixed>

Sorting settings. For example [ 'field' => 'id' , 'order' => 'ASC' ]

Return values
string

Compiled sorting settings

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[, mixed $param = '' ]) : string
Parameters
$urlLocator : string

url locator

$param : mixed = ''

extra param

Return values
string

concrete URL

isFile()

Checking if we are uploading a file

protected isFile(mixed $value) : bool
Parameters
$value : mixed

Uploading data

Return values
bool

True if the $value is the uploading file. False otherwise

pretransformData()

Transforming data before sending to service

protected pretransformData(array<string|int, mixed> $data) : string
Parameters
$data : array<string|int, mixed>

Data to be transformed

Return values
string

Transformed data

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