Skip to content

AttributeBag

Simple immutable-style attribute bag for no-container execution path.

Provides a focused API; mutation returns a cloned instance.

class AttributeBag implements ArrayAccess, Countable, IteratorAggregate

ImplementsArrayAccess, Countable, IteratorAggregate
SourceExecution/AttributeBag.php

public function __construct(array<string, mixed> $data = []): mixed

ParameterTypeDescription
$dataarray``<``string``, ``mixed``>

Returns mixed

MethodDescription
all(): array<string, mixed>
count(): intReturns the number of entries currently held.
get(string $key, mixed $default = null): mixed
getIterator(): TraversableReturns an iterator over the entries, keyed by attribute name.
has(string $key): boolReports whether the bag holds an entry under the given key, including one whose value is null.
merge(array<string, mixed> $values): AttributeBag
offsetExists(mixed $offset): boolReports whether an entry exists under the offset, treating a stored null as present.
offsetGet(mixed $offset): mixedReturns the value stored under the offset, or null when nothing is stored there.
offsetSet(mixed $offset, mixed $value): voidStores a value under the offset, mutating this bag in place.
offsetUnset(mixed $offset): voidRemoves the entry under the offset, mutating this bag in place; an absent key is a no-op.
with(string $key, mixed $value): AttributeBag
without(string $key): AttributeBagReturns a clone of the bag with the given key removed.

public function all(): array<string, mixed>

Returns array``<``string``, ``mixed``>

public function count(): int

Returns the number of entries currently held.

Returns int

public function get(string $key, mixed $default = null): mixed

ParameterTypeDescription
$keystring
$defaultmixed

Returns mixed

public function getIterator(): Traversable

Returns an iterator over the entries, keyed by attribute name.

The iterator walks a snapshot taken at call time, so mutating the bag afterwards does not affect an iteration already in progress.

Returns Traversable

public function has(string $key): bool

Reports whether the bag holds an entry under the given key, including one whose value is null.

ParameterTypeDescription
$keystring

Returns bool

public function merge(array<string, mixed> $values): AttributeBag

ParameterTypeDescription
$valuesarray``<``string``, ``mixed``>

Returns AttributeBag

public function offsetExists(mixed $offset): bool

Reports whether an entry exists under the offset, treating a stored null as present.

ParameterTypeDescription
$offsetmixed

Returns bool

public function offsetGet(mixed $offset): mixed

Returns the value stored under the offset, or null when nothing is stored there.

ParameterTypeDescription
$offsetmixed

Returns mixed

public function offsetSet(mixed $offset, mixed $value): void

Stores a value under the offset, mutating this bag in place.

Callers that want the immutable semantics of the bag should use with() instead.

ParameterTypeDescription
$offsetmixed
$valuemixed
ThrowsWhen
InvalidArgumentExceptionIf the offset is not a string.

public function offsetUnset(mixed $offset): void

Removes the entry under the offset, mutating this bag in place; an absent key is a no-op.

ParameterTypeDescription
$offsetmixed

public function with(string $key, mixed $value): AttributeBag

ParameterTypeDescription
$keystring
$valuemixed

Returns AttributeBag

public function without(string $key): AttributeBag

Returns a clone of the bag with the given key removed.

The receiver is never modified. When the key is absent the same instance is returned rather than a clone, since there is nothing to change.

ParameterTypeDescription
$keystring

Returns AttributeBag