Documentation

PostgrestSyncClient extends PostgrestBaseClient
in package
implements PostgrestClientInterface

PostgrestSyncClient is a synchronous client for PostgREST.

Table of Contents

Interfaces

PostgrestClientInterface
Interface for both synchronous and asynchronous PostgREST clients.

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.
auth()  : bool
Authenticate the client synchronously using stored procedure
call()  : PostgrestResponse
Call a stored procedure synchronously.
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.
run()  : PostgrestResponse
Run a request synchronously.
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.

call()

Call a stored procedure synchronously.

public call(string $functionName[, array<string, mixed> $params = [] ][, string $schemaName = 'public' ][, bool $skipAuth = false ]) : 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

Whether to skip authentication.

Tags
throws
FailedAuthException

If the request fails due to authentication (only applicable with autoAuth enabled).

throws
PostgrestErrorException

If the request fails.

link
https://postgrest.org/en/stable/references/api/stored_procedures.html
Return values
PostgrestResponse

The response.

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.

run()

Run a request synchronously.

public run(PostgrestRequestBuilder $requestBuilder[, bool $skipAuth = false ]) : PostgrestResponse
Parameters
$requestBuilder : PostgrestRequestBuilder

The request builder.

$skipAuth : bool = false

Whether to skip authentication.

Tags
throws
FailedAuthException

If the request fails due to authentication (only applicable with autoAuth enabled).

throws
PostgrestErrorException

If the request fails.

link
https://postgrest.org/en/stable/references/api/tables_views.html
Return values
PostgrestResponse

The response.

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