EffectsRequestBuilder
extends RequestBuilder
in package
Builds requests for the effects endpoint in Horizon
This class provides methods to query effects on the Stellar network. Effects represent specific changes that occur in the ledger as a result of successful operations. Each operation can produce multiple effects (e.g., a payment operation produces a debit effect for the sender and a credit effect for the receiver).
Query Methods:
- forAccount(): Get effects for a specific account
- forLedger(): Get effects in a specific ledger
- forTransaction(): Get effects from a specific transaction
- forOperation(): Get effects from a specific operation
- forLiquidityPool(): Get effects for a specific liquidity pool
Effects provide a detailed view of ledger changes and are useful for building account activity feeds and transaction history displays.
Usage Examples:
// Get recent effects for an account $effects = $sdk->effects() ->forAccount("GDAT5...") ->limit(20) ->order("desc") ->execute();
// Stream real-time effects $sdk->effects() ->cursor("now") ->stream(function(EffectResponse $effect) { echo "Effect: " . $effect->getType() . PHP_EOL; });
// Get effects for a specific operation $effects = $sdk->effects() ->forOperation("123456789") ->execute();
Tags
Table of Contents
Constants
- HEADERS = ["X-Client-Name" => "stellar_php_sdk", "X-Client-Version" => \Soneso\StellarSDK\StellarSDK::VERSION_NR]
Properties
- $httpClient : Client
- $queryParameters : array<string|int, mixed>
- $segments : array<string|int, mixed>
Methods
- __construct() : mixed
- Constructor
- buildUrl() : string
- Builds the complete request URL with all segments and query parameters
- cursor() : EffectsRequestBuilder
- Sets <code>cursor</code> parameter on the request.
- execute() : Response
- Build and execute request.
- executeRequest() : Response
- Executes an HTTP request to Horizon and returns a parsed response object
- forAccount() : EffectsRequestBuilder
- Builds request to <code>GET /accounts/{account}/effects</code>
- forLedger() : EffectsRequestBuilder
- Builds request to <code>GET /ledgers/{ledgerSeq}/effects</code>
- forLiquidityPool() : EffectsRequestBuilder
- Builds request to <code>GET /liquidity_pools/{poolID}/effects</code>
- forOperation() : EffectsRequestBuilder
- Builds request to <code>GET /operation/{operationId}/effects</code>
- forTransaction() : EffectsRequestBuilder
- Builds request to <code>GET /transactions/{transactionId}/effects</code>
- getAndStream() : void
- Streams Server-Sent Events from Horizon to a callback function
- limit() : EffectsRequestBuilder
- Sets <code>limit</code> parameter on the request.
- order() : EffectsRequestBuilder
- Sets <code>order</code> parameter on the request.
- request() : EffectsPageResponse
- Requests specific <code>url</code> and returns {@link EffectsPageResponse}.
- stream() : mixed
- Streams Effect objects to $callback
- setSegments() : RequestBuilder
- Sets the URL path segments for this request
Constants
HEADERS
public
mixed
HEADERS
= ["X-Client-Name" => "stellar_php_sdk", "X-Client-Version" => \Soneso\StellarSDK\StellarSDK::VERSION_NR]
Properties
$httpClient
protected
Client
$httpClient
$queryParameters
protected
array<string|int, mixed>
$queryParameters
$segments
protected
array<string|int, mixed>
$segments
Methods
__construct()
Constructor
public
__construct(Client $httpClient) : mixed
Parameters
- $httpClient : Client
-
The HTTP client used for making requests to Horizon
buildUrl()
Builds the complete request URL with all segments and query parameters
public
buildUrl() : string
Combines the URL path segments with query parameters to create the final request URL string that will be sent to Horizon.
Return values
string —The constructed URL with query parameters
cursor()
Sets <code>cursor</code> parameter on the request.
public
cursor(string $cursor) : EffectsRequestBuilder
A cursor is a value that points to a specific location in a collection of resources. The cursor attribute itself is an opaque value meaning that users should not try to parse it.
Parameters
- $cursor : string
Tags
Return values
EffectsRequestBuilderexecute()
Build and execute request.
public
execute() : Response
@throws HorizonRequestException
Return values
Response —The parsed response object
executeRequest()
Executes an HTTP request to Horizon and returns a parsed response object
public
executeRequest(string $url, string $requestType[, string|null $requestMethod = "GET" ]) : Response
This method sends the HTTP request to the Horizon server, handles errors, and parses the JSON response into the appropriate response type.
Parameters
- $url : string
-
The complete request URL to fetch
- $requestType : string
-
The expected response type for parsing
- $requestMethod : string|null = "GET"
-
The HTTP method to use (default: "GET")
Tags
Return values
Response —The parsed response object of the specified type
forAccount()
Builds request to <code>GET /accounts/{account}/effects</code>
public
forAccount(string $accountId) : EffectsRequestBuilder
Parameters
- $accountId : string
-
ID of the account for which to get effects.
Tags
Return values
EffectsRequestBuilderforLedger()
Builds request to <code>GET /ledgers/{ledgerSeq}/effects</code>
public
forLedger(string $ledgerSeq) : EffectsRequestBuilder
Parameters
- $ledgerSeq : string
-
Ledger for which to get effects.
Tags
Return values
EffectsRequestBuilderforLiquidityPool()
Builds request to <code>GET /liquidity_pools/{poolID}/effects</code>
public
forLiquidityPool(string $liquidityPoolId) : EffectsRequestBuilder
Parameters
- $liquidityPoolId : string
-
Liquidity pool for which to get effects.
Tags
Return values
EffectsRequestBuilderforOperation()
Builds request to <code>GET /operation/{operationId}/effects</code>
public
forOperation(string $operationId) : EffectsRequestBuilder
Parameters
- $operationId : string
-
ID of operation for which to get effects.
Tags
Return values
EffectsRequestBuilderforTransaction()
Builds request to <code>GET /transactions/{transactionId}/effects</code>
public
forTransaction(string $transactionId) : EffectsRequestBuilder
Parameters
- $transactionId : string
-
Transaction ID for which to get effects.
Tags
Return values
EffectsRequestBuildergetAndStream()
Streams Server-Sent Events from Horizon to a callback function
public
getAndStream(string $relativeUrl, callable $callback[, bool $retryOnServerException = true ]) : void
This method establishes a persistent connection to Horizon's streaming endpoints using Server-Sent Events (SSE). It processes each event and passes the parsed data to the provided callback function. The stream automatically reconnects on server exceptions if retryOnServerException is true.
Horizon streaming uses SSE to push real-time updates. The stream sends:
- "hello" message on connection
- "byebye" message on disconnection
- JSON data objects for actual events
Parameters
- $relativeUrl : string
-
The relative URL to stream from
- $callback : callable
-
Function to receive parsed event data
- $retryOnServerException : bool = true
-
If true, automatically retry on server errors (default: true)
Tags
Return values
void —This method runs indefinitely until interrupted
limit()
Sets <code>limit</code> parameter on the request.
public
limit(int $number) : EffectsRequestBuilder
It defines maximum number of records to return. For range and default values check documentation of the endpoint requested.
Parameters
- $number : int
-
Maximum number of records to return
Return values
EffectsRequestBuilderorder()
Sets <code>order</code> parameter on the request.
public
order([string $direction = "asc" ]) : EffectsRequestBuilder
Parameters
- $direction : string = "asc"
-
"asc" or "desc"
Return values
EffectsRequestBuilderrequest()
Requests specific <code>url</code> and returns {@link EffectsPageResponse}.
public
request(string $url) : EffectsPageResponse
Parameters
- $url : string
Tags
Return values
EffectsPageResponsestream()
Streams Effect objects to $callback
public
stream([callable|null $callback = null ]) : mixed
$callback should have arguments: EffectResponse
For example:
$sdk = StellarSDK::getTestNetInstance(); $sdk->effects()->cursor("now")->stream(function(EffectResponse $effect) { printf('Effect type: %s' . PHP_EOL, $effect->getEffectType()); });
Parameters
- $callback : callable|null = null
Tags
setSegments()
Sets the URL path segments for this request
protected
setSegments(string ...$segments) : RequestBuilder
This method constructs the URL path by combining multiple segments. Can only be called once per request builder instance.
Parameters
- $segments : string
-
Variable number of URL path segments
Tags
Return values
RequestBuilder —This instance for method chaining