Parse PHP SDK API Reference

ParseClient
in package

Class ParseClient - Main class for Parse initialization and communication.

Tags
author

Fosco Marotto [email protected]

Table of Contents

VERSION_STRING  = '2.4.0'
Constant for version string to include with requests.
$applicationId  : string
The application id.
$caFile  : string
CA file holding one or more certificates to verify a peer
$connectionTimeout  : int
Number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
$enableCurlExceptions  : bool
Enable/Disable curl exceptions.
$forceRevocableSession  : bool
Are revocable sessions enabled?
$httpClient  : ParseHttpable
Http client for requests
$httpOptions  : array<string|int, mixed>
Options to pass to the http client.
$masterKey  : string
The Master Key.
$mountPath  : string
The mount path for the current parse server
$restKey  : string|null
The REST API Key.
$serverURL  : string
The remote Parse Server to communicate with
$storage  : ParseStorageInterface
The object for managing persistence.
$timeout  : int
Maximum number of seconds of request/response operation.
_clearMountPath()  : mixed
Clears the existing mount path.
_clearServerURL()  : mixed
Clears the existing server url.
_decode()  : mixed
ParseClient::_decode, internal method for decoding server responses.
_encode()  : mixed
ParseClient::_encode, internal method for encoding object values.
_encodeArray()  : array<string|int, mixed>
ParseClient::_encodeArray, internal method for encoding arrays.
_request()  : mixed
Parse\Client::_request, internal method for communicating with Parse.
_unsetStorage()  : mixed
ParseClient::_unsetStorage, will null the storage object.
clearHttpClient()  : mixed
Clears the currently set http client
enableRevocableSessions()  : mixed
Allows an existing application to start using revocable sessions, without forcing all requests for the app to use them. After calling this method, login & signup requests will be returned a unique and revocable session token.
getAPIUrl()  : string
Get remote Parse API url.
getHttpClient()  : ParseHttpable
Gets the current Http client, or creates one to suite the need
getMountPath()  : string
Get remote Parse API mount path
getProperDateFormat()  : string
Get a date value in the format stored on Parse.
getPushDateFormat()  : string
Get a date value in the format to use in Local Push Scheduling on Parse.
getServerHealth()  : array<string|int, mixed>
Returns an array of information regarding the current server's health
getStorage()  : ParseStorageInterface
ParseClient::getStorage, will return the storage object used for persistence.
initialize()  : mixed
Parse\Client::initialize, must be called before using Parse features.
setCAFile()  : mixed
Sets a CA file to validate peers of our requests with
setConnectionTimeout()  : mixed
Sets number of seconds to wait while trying to connect. Use 0 to wait indefinitely, null to default behaviour.
setHttpClient()  : mixed
Sets the Http client to use for requests
setHttpOptions()  : mixed
Sets http options to pass to the http client For curl https://www.php.net/manual/en/function.curl-setopt.php
setServerURL()  : mixed
ParseClient::setServerURL, to change the Parse Server address & mount path for this app
setStorage()  : mixed
ParseClient::setStorage, will update the storage object used for persistence.
setTimeout()  : mixed
Sets maximum number of seconds of request/response operation.
assertParseInitialized()  : mixed
Asserts that the sdk has been initialized with a valid application id
assertServerInitialized()  : mixed
Asserts that the server and mount path have been initialized
createRequestUrl()  : string
Creates an absolute request url from a relative one
getLastJSONErrorMsg()  : string
Returns the last error message from a failed json_decode call
getPreparedHttpClient()  : ParseHttpable
Returns an httpClient prepared for use

Constants

VERSION_STRING

Constant for version string to include with requests.

public string VERSION_STRING = '2.4.0'

Properties

$applicationId

The application id.

private static string $applicationId

$caFile

CA file holding one or more certificates to verify a peer

private static string $caFile

$connectionTimeout

Number of seconds to wait while trying to connect. Use 0 to wait indefinitely.

private static int $connectionTimeout

$enableCurlExceptions

Enable/Disable curl exceptions.

private static bool $enableCurlExceptions

$forceRevocableSession

Are revocable sessions enabled?

private static bool $forceRevocableSession = false

$httpOptions

Options to pass to the http client.

private static array<string|int, mixed> $httpOptions

$masterKey

The Master Key.

private static string $masterKey

$mountPath

The mount path for the current parse server

private static string $mountPath = null

$restKey

The REST API Key.

private static string|null $restKey

$serverURL

The remote Parse Server to communicate with

private static string $serverURL = null

$timeout

Maximum number of seconds of request/response operation.

private static int $timeout

Methods

_clearMountPath()

Clears the existing mount path.

public static _clearMountPath() : mixed

Used primarily for testing purposes.

Return values
mixed —

_clearServerURL()

Clears the existing server url.

public static _clearServerURL() : mixed

Used primarily for testing purposes.

Return values
mixed —

_decode()

ParseClient::_decode, internal method for decoding server responses.

public static _decode(mixed $data) : mixed
Parameters
$data : mixed

The value to decode

Return values
mixed —

_encode()

ParseClient::_encode, internal method for encoding object values.

public static _encode(mixed $value, bool $allowParseObjects) : mixed
Parameters
$value : mixed

Value to encode

$allowParseObjects : bool

Allow nested objects

Tags
throws
Exception
Return values
mixed —

Encoded results.

_encodeArray()

ParseClient::_encodeArray, internal method for encoding arrays.

public static _encodeArray(array<string|int, mixed> $value, bool $allowParseObjects) : array<string|int, mixed>
Parameters
$value : array<string|int, mixed>

Array to encode.

$allowParseObjects : bool

Allow nested objects.

Return values
array<string|int, mixed> —

Encoded results.

_request()

Parse\Client::_request, internal method for communicating with Parse.

public static _request(string $method, string $relativeUrl[, null $sessionToken = null ][, null $data = null ][, bool $useMasterKey = false ][, string $contentType = 'application/json' ][, bool $returnHeaders = false ]) : mixed
Parameters
$method : string

HTTP Method for this request.

$relativeUrl : string

REST API Path.

$sessionToken : null = null

Session Token.

$data : null = null

Data to provide with the request.

$useMasterKey : bool = false

Whether to use the Master Key.

$contentType : string = 'application/json'

The content type for this request, default is application/json

$returnHeaders : bool = false

Allow to return response headers

Tags
throws
Exception
Return values
mixed —

Result from Parse API Call.

_unsetStorage()

ParseClient::_unsetStorage, will null the storage object.

public static _unsetStorage() : mixed

Without some ability to clear the storage objects, all test cases would use the first assigned storage object.

Return values
mixed —

clearHttpClient()

Clears the currently set http client

public static clearHttpClient() : mixed
Return values
mixed —

enableRevocableSessions()

Allows an existing application to start using revocable sessions, without forcing all requests for the app to use them. After calling this method, login & signup requests will be returned a unique and revocable session token.

public static enableRevocableSessions() : mixed
Return values
mixed —

getAPIUrl()

Get remote Parse API url.

public static getAPIUrl() : string
Return values
string —

getMountPath()

Get remote Parse API mount path

public static getMountPath() : string
Return values
string —

getProperDateFormat()

Get a date value in the format stored on Parse.

public static getProperDateFormat(DateTime $value) : string

All the SDKs do some slightly different date handling. PHP provides 6 digits for the microseconds (u) so we have to chop 3 off.

Parameters
$value : DateTime

DateTime value to format.

Return values
string —

getPushDateFormat()

Get a date value in the format to use in Local Push Scheduling on Parse.

public static getPushDateFormat(DateTime $value[, bool $local = false ]) : string

All the SDKs do some slightly different date handling. Format from Parse doc: an ISO 8601 date without a time zone, i.e. 2014-10-16T12:00:00 .

Parameters
$value : DateTime

DateTime value to format.

$local : bool = false

Whether to return the local push time

Return values
string —

getServerHealth()

Returns an array of information regarding the current server's health

public static getServerHealth() : array<string|int, mixed>
Return values
array<string|int, mixed> —

initialize()

Parse\Client::initialize, must be called before using Parse features.

public static initialize(string $app_id, string $rest_key, string $master_key[, bool $enableCurlExceptions = true ]) : mixed
Parameters
$app_id : string

Parse Application ID

$rest_key : string

Parse REST API Key

$master_key : string

Parse Master Key

$enableCurlExceptions : bool = true

Enable or disable Parse curl exceptions

Tags
throws
Exception
Return values
mixed —

setCAFile()

Sets a CA file to validate peers of our requests with

public static setCAFile(string $caFile) : mixed
Parameters
$caFile : string

CA file to set

Return values
mixed —

setConnectionTimeout()

Sets number of seconds to wait while trying to connect. Use 0 to wait indefinitely, null to default behaviour.

public static setConnectionTimeout(int|null $connectionTimeout) : mixed
Parameters
$connectionTimeout : int|null
Return values
mixed —

setHttpClient()

Sets the Http client to use for requests

public static setHttpClient(ParseHttpable $httpClient) : mixed
Parameters
$httpClient : ParseHttpable

Http client to use

Return values
mixed —

setHttpOptions()

Sets http options to pass to the http client For curl https://www.php.net/manual/en/function.curl-setopt.php

public static setHttpOptions(array<string|int, mixed> $httpOptions) : mixed

For stream context https://www.php.net/manual/en/context.php

Parameters
$httpOptions : array<string|int, mixed>

options to set

Return values
mixed —

setServerURL()

ParseClient::setServerURL, to change the Parse Server address & mount path for this app

public static setServerURL(string $serverURL, string $mountPath) : mixed
Parameters
$serverURL : string

The remote server url

$mountPath : string

The mount path for this server

Tags
throws
Exception
Return values
mixed —

setTimeout()

Sets maximum number of seconds of request/response operation.

public static setTimeout(int|null $timeout) : mixed

Use 0 to wait indefinitely, null to default behaviour.

Parameters
$timeout : int|null
Return values
mixed —

assertParseInitialized()

Asserts that the sdk has been initialized with a valid application id

private static assertParseInitialized() : mixed
Tags
throws
Exception
Return values
mixed —

assertServerInitialized()

Asserts that the server and mount path have been initialized

private static assertServerInitialized() : mixed
Tags
throws
Exception
Return values
mixed —

createRequestUrl()

Creates an absolute request url from a relative one

private static createRequestUrl(string $relativeUrl) : string
Parameters
$relativeUrl : string

Relative url to create full request url from

Return values
string —

getLastJSONErrorMsg()

Returns the last error message from a failed json_decode call

private static getLastJSONErrorMsg() : string
Return values
string —

Search results