PostgrestBaseClient
in package
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
$authArguments
protected
array<string, mixed>|null
$authArguments
$authFunctionName
protected
string
$authFunctionName
$authHeader
protected
string|null
$authHeader
= null
$authSchemaName
protected
string
$authSchemaName
$autoAuth
protected
bool
$autoAuth
$tokenExpirationTime
protected
int
$tokenExpirationTime
= 0
$autoAuthGrace
private
int
$autoAuthGrace
$baseUrl
private
string
$baseUrl
= 'http://localhost/'
$currentlyInReAuth
private
bool
$currentlyInReAuth
= false
$httpClient
private
Browser
$httpClient
= new Browser()
$timeout
private
int
$timeout
= 15
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.
from()
Create a new request builder for a table in a schema.
public
final from(string $schemaName, string $tableName) : PostgrestRequestBuilder
Parameters
- $schemaName : string
-
The schema name of the table.
- $tableName : string
-
The table name.
Return values
PostgrestRequestBuilder —The request builder.
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
_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.
_run()
Run a request.
protected
final _run(PostgrestRequestBuilder $requestBuilder[, bool $skipAuth = false ]) : PromiseInterface<string|int, PostgrestResponse>
Parameters
- $requestBuilder : PostgrestRequestBuilder
-
The request builder.
- $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.