Documentation

PostgrestBaseClient
in package

AbstractYes

The PostgrestBaseClient holds all general functionality for the PostgREST client.

Both the sync and async clients extend this class.

Table of Contents

Properties

$authArguments  : array<string, mixed>|null
$authFunctionName  : string
$authHeader  : string|null
$authSchemaName  : string
$autoAuth  : bool
$tokenExpirationTime  : int
$autoAuthGrace  : int
$baseUrl  : string
$currentlyInReAuth  : bool
$httpClient  : Browser
$timeout  : int

Methods

__construct()  : mixed
Create new PostgREST client.
disableAutoAuth()  : void
Disable auto authentication feature
enableAutoAuth()  : void
Enable auto authentication feature.
from()  : PostgrestRequestBuilder
Create a new request builder for a table in a schema.
getTokenExpirationTime()  : int
Returns the expiration time of the authentication token.
isAuthenticated()  : bool
Check whether the client is authenticated.
setAuthToken()  : void
Function to manually set authentication token.
_auth()  : PromiseInterface<string|int, bool>
Authenticate the client using stored procedure.
_call()  : PromiseInterface<string|int, PostgrestResponse>
Call a stored procedure.
_execute()  : PromiseInterface<string|int, PostgrestResponse>
Execute a request.
_run()  : PromiseInterface<string|int, PostgrestResponse>
Run a request.
createRequestPromise()  : PromiseInterface<string|int, ResponseInterface>
Sends the request and optionally prepends the authentication.

Properties

Methods

__construct()

Create new PostgREST client.

public final __construct([string $baseUrl = 'http://localhost/' ][, int $timeout = 15 ][, Browser $httpClient = new Browser() ][, ClientAuthConfig $clientAuthConfig = new ClientAuthConfig() ]) : mixed
Parameters
$baseUrl : string = 'http://localhost/'

The base URI of the PostgREST server.

$timeout : int = 15

The timeout in seconds for the HTTP requests.

$httpClient : Browser = new Browser()

The HTTP client.

$clientAuthConfig : ClientAuthConfig = new ClientAuthConfig()

Extra client configuration.

disableAutoAuth()

Disable auto authentication feature

public final disableAutoAuth() : void

Will disable check token expiration with every request

enableAutoAuth()

Enable auto authentication feature.

public final enableAutoAuth([int $autoAuthGrace = 300 ]) : void

Will enable check token expiration with every request.

Parameters
$autoAuthGrace : int = 300

The grace period in seconds which will be subtracted from the token expiration time.

getTokenExpirationTime()

Returns the expiration time of the authentication token.

public final getTokenExpirationTime() : int
Return values
int

Token expiration time

isAuthenticated()

Check whether the client is authenticated.

public final isAuthenticated() : bool

When autoAuth is enabled, the autoAuthGrace + timeout will be subtracted from the token expiration time. If autoAuth is disabled, the timeout * 2 will be subtracted.

Return values
bool

Whether the client is authenticated.

setAuthToken()

Function to manually set authentication token.

public final setAuthToken(string $token) : void

Useful when not using stored procedure for authentication.

Parameters
$token : string

The JWT token.

Tags
throws
FailedAuthException

If the token is invalid.

_auth()

Authenticate the client using stored procedure.

protected final _auth() : PromiseInterface<string|int, bool>
Return values
PromiseInterface<string|int, bool>

The response.

_call()

Call a stored procedure.

protected final _call(string $functionName[, array<string, mixed> $params = [] ][, string $schemaName = 'public' ][, bool $skipAuth = false ]) : PromiseInterface<string|int, PostgrestResponse>
Parameters
$functionName : string

The function name.

$params : array<string, mixed> = []

The parameters for the function.

$schemaName : string = 'public'

The schema name of the function.

$skipAuth : bool = false
Return values
PromiseInterface<string|int, PostgrestResponse>

The response.

_execute()

Execute a request.

protected final _execute(string $method, string $url, array<string|int, array<string, mixed>> $headers, string $body[, bool $skipAuth = false ]) : PromiseInterface<string|int, PostgrestResponse>
Parameters
$method : string

The HTTP method.

$url : string

The URL.

$headers : array<string|int, array<string, mixed>>

Additional request options.

$body : string
$skipAuth : bool = false

Whether to skip authentication (only applied when autoAuth enabled).

Return values
PromiseInterface<string|int, PostgrestResponse>

The response.

createRequestPromise()

Sends the request and optionally prepends the authentication.

private createRequestPromise(string $method, string $url, array<string|int, array<string, mixed>> $headers, string $body[, bool $skipAuth = false ]) : PromiseInterface<string|int, ResponseInterface>
Parameters
$method : string

The HTTP method.

$url : string

The URL.

$headers : array<string|int, array<string, mixed>>

Additional request options.

$body : string
$skipAuth : bool = false

Whether to skip authentication (only applied when autoAuth enabled).

Return values
PromiseInterface<string|int, ResponseInterface>

The response.


        
On this page

Search results