AttributeBag
Simple immutable-style attribute bag for no-container execution path.
Provides a focused API; mutation returns a cloned instance.
Synopsis
Section titled “Synopsis”class AttributeBag implements ArrayAccess, Countable, IteratorAggregate
| Implements | ArrayAccess, Countable, IteratorAggregate |
| Source | Execution/AttributeBag.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(array<string, mixed> $data = []): mixed
| Parameter | Type | Description |
|---|---|---|
$data | array``<``string``, ``mixed``> |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
all(): array<string, mixed> | |
count(): int | Returns the number of entries currently held. |
get(string $key, mixed $default = null): mixed | |
getIterator(): Traversable | Returns an iterator over the entries, keyed by attribute name. |
has(string $key): bool | Reports 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): bool | Reports whether an entry exists under the offset, treating a stored null as present. |
offsetGet(mixed $offset): mixed | Returns the value stored under the offset, or null when nothing is stored there. |
offsetSet(mixed $offset, mixed $value): void | Stores a value under the offset, mutating this bag in place. |
offsetUnset(mixed $offset): void | Removes 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): AttributeBag | Returns a clone of the bag with the given key removed. |
public function all(): array<string, mixed>
Returns array``<``string``, ``mixed``>
count()
Section titled “count()”public function count(): int
Returns the number of entries currently held.
Returns int
public function get(string $key, mixed $default = null): mixed
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$default | mixed |
Returns mixed
getIterator()
Section titled “getIterator()”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.
| Parameter | Type | Description |
|---|---|---|
$key | string |
Returns bool
merge()
Section titled “merge()”public function merge(array<string, mixed> $values): AttributeBag
| Parameter | Type | Description |
|---|---|---|
$values | array``<``string``, ``mixed``> |
Returns AttributeBag
offsetExists()
Section titled “offsetExists()”public function offsetExists(mixed $offset): bool
Reports whether an entry exists under the offset, treating a stored null as present.
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
Returns bool
offsetGet()
Section titled “offsetGet()”public function offsetGet(mixed $offset): mixed
Returns the value stored under the offset, or null when nothing is stored there.
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
Returns mixed
offsetSet()
Section titled “offsetSet()”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.
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed |
| Throws | When |
|---|---|
InvalidArgumentException | If the offset is not a string. |
offsetUnset()
Section titled “offsetUnset()”public function offsetUnset(mixed $offset): void
Removes the entry under the offset, mutating this bag in place; an absent key is a no-op.
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
with()
Section titled “with()”public function with(string $key, mixed $value): AttributeBag
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$value | mixed |
Returns AttributeBag
without()
Section titled “without()”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.
| Parameter | Type | Description |
|---|---|---|
$key | string |
Returns AttributeBag