Flow PHP

Baggage implements Countable

Read onlyYes
FinalYes

Key-value store for data propagation across process boundaries.

Baggage allows you to propagate arbitrary data along with a trace, similar to HTTP headers but specifically designed for distributed tracing.

All operations return new Baggage instances (immutable).

Example usage:

$baggage = new Baggage(['user.id' => '12345']);
$baggage = $baggage->with('request.id', 'abc-123');
echo $baggage->get('user.id'); // "12345"

Interfaces

Countable

Methods

__construct()  : mixed
all()  : array<string, string>
Get all entries.
count()  : int
Get the number of entries.
fromArray()  : self
Create a Baggage from a normalized array representation.
get()  : null|string
Get the value of an entry.
has()  : bool
Check if an entry exists.
isEmpty()  : bool
Check if the baggage is empty.
normalize()  : array{entries: array}
Normalize the Baggage to an array representation for serialization.
with()  : self
Create a new Baggage with an additional entry.
without()  : self
Create a new Baggage without the specified entry.

Methods

__construct()

public __construct([array<string, string> $entries = [] ]) : mixed
Parameters
$entries : array<string, string> = []

all()

Get all entries.

public all() : array<string, string>
Return values
array<string, string>

count()

Get the number of entries.

public count() : int
Return values
int

fromArray()

Create a Baggage from a normalized array representation.

public static fromArray(array{entries: array$data) : self
Parameters
$data : array{entries: array}

Normalized Baggage data

Return values
self

get()

Get the value of an entry.

public get(string $key) : null|string
Parameters
$key : string

Entry key

Return values
null|string

The entry value, or null if not found

has()

Check if an entry exists.

public has(string $key) : bool
Parameters
$key : string

Entry key

Return values
bool

isEmpty()

Check if the baggage is empty.

public isEmpty() : bool
Return values
bool

normalize()

Normalize the Baggage to an array representation for serialization.

public normalize() : array{entries: array}
Return values
array{entries: array}

with()

Create a new Baggage with an additional entry.

public with(string $key, string $value) : self

If the key already exists, its value will be replaced.

Parameters
$key : string

Entry key

$value : string

Entry value

Return values
self

New Baggage instance with the added entry

without()

Create a new Baggage without the specified entry.

public without(string $key) : self
Parameters
$key : string

Entry key to remove

Return values
self

New Baggage instance without the entry


        
On this page

Search results