class ComponentAttributeBag implements Arrayable, ArrayAccess, IteratorAggregate, JsonSerializable, Htmlable, Stringable

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected array $attributes

The raw array of attributes.

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

array
all(mixed $keys = null)

Get all the attribute values.

mixed
data(string|null $key = null, mixed $default = null)

Retrieve data from the instance.

bool
exists(array|string $key)

Determine if the data contains a given key.

bool
has(array|string $key)

Determine if the data contains a given key.

bool
hasAny(array|string $keys)

Determine if the instance contains any of the given keys.

mixed
whenHas(string $key, callable $callback, callable|null $default = null)

Apply the callback if the instance contains the given key.

bool
filled(array|string $key)

Determine if the instance contains a non-empty value for the given key.

bool
isNotFilled(array|string $key)

Determine if the instance contains an empty value for the given key.

bool
anyFilled(array|string $keys)

Determine if the instance contains a non-empty value for any of the given keys.

mixed
whenFilled(string $key, callable $callback, callable|null $default = null)

Apply the callback if the instance contains a non-empty value for the given key.

mixed
whenEnum(string $key, string $enumClass, callable $callback, callable|null $default = null)

Apply the callback if the instance contains a valid enum value for the given key.

bool
missing(array|string $key)

Determine if the instance is missing a given key.

mixed
whenMissing(string $key, callable $callback, callable|null $default = null)

Apply the callback if the instance is missing the given key.

bool
isEmptyString(string $key)

Determine if the given key is an empty string for "filled".

str(string $key, mixed $default = null)

Retrieve data from the instance as a Stringable instance.

string(string $key, mixed $default = null)

Retrieve data from the instance as a Stringable instance.

bool
boolean(string|null $key = null, bool $default = false)

Retrieve data as a boolean value.

int
integer(string $key, int $default = 0)

Retrieve data as an integer value.

float
float(string $key, float $default = 0.0)

Retrieve data as a float value.

int|float
clamp(string $key, int|float $min, int|float $max, int|float $default = 0)

Retrieve data clamped between min and max values.

CarbonInterface|null
date(string $key, string|null $format = null, UnitEnum|string|null $tz = null)

Retrieve data from the instance as a Carbon instance.

CarbonInterval|null
interval(string $key, Unit|string|null $unit = null)

Retrieve data from the instance as a CarbonInterval instance.

mixed
enum(string $key, string $enumClass, mixed $default = null)

Retrieve data from the instance as an enum.

array
enums(string $key, string $enumClass)

Retrieve data from the instance as an array of enums.

bool
isBackedEnum(string $enumClass)

Determine if the given enum class is backed.

int|string|null
normalizeEnumValue(string $enumClass, mixed $value)

Normalize enum input to a strict backed value.

string|null
enumBackingType(string $enumClass)

Resolve and cache the enum backing type for repeated lookups.

array
array(array|string|null $key = null)

Retrieve data from the instance as an array.

collect(array|string|null $key = null)

Retrieve data from the instance as a collection.

only(mixed $keys)

Only include the given attribute from the attribute array.

except(mixed $keys)

Exclude the given attribute from the attribute array.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(array $attributes = [])

Create a new component attribute bag instance.

mixed
first(mixed $default = null)

Get the first attribute's value.

mixed
get(string $key, mixed $default = null)

Get a given attribute from the attribute array.

filter(callable $callback)

Filter the attributes, returning a bag of attributes that pass the filter.

whereStartsWith(string|array $needles)

Return a bag of attributes that have keys starting with the given value / pattern.

whereDoesntStartWith(string|array $needles)

Return a bag of attributes with keys that do not start with the given value / pattern.

thatStartWith(string|array $needles)

Return a bag of attributes that have keys starting with the given value / pattern.

onlyProps(mixed $keys)

Only include the given attribute from the attribute array.

exceptProps(mixed $keys)

Exclude the given attribute from the attribute array.

class(mixed $classList)

Conditionally merge classes into the attribute bag.

style(mixed $styleList)

Conditionally merge styles into the attribute bag.

merge(array $attributeDefaults = [], bool $escape = true)

Merge additional attributes / values into the attribute bag.

bool
shouldEscapeAttributeValue(bool $escape, mixed $value)

Determine if the specific attribute value should be escaped.

prepends(mixed $value)

Create a new appendable attribute value.

mixed
resolveAppendableAttributeDefault(array $attributeDefaults, string $key, bool $escape)

Resolve an appendable attribute value default value.

bool
isEmpty()

Determine if the attribute bag is empty.

bool
isNotEmpty()

Determine if the attribute bag is not empty.

array
getAttributes()

Get all of the raw attributes.

void
setAttributes(array $attributes)

Set the underlying attributes.

static array
extractPropNames(array $keys)

Extract "prop" names from given keys.

string
toHtml()

Get content as a string of HTML.

__invoke(array $attributeDefaults = [])

Merge additional attributes / values into the attribute bag.

bool
offsetExists(mixed $offset)

Determine if the given offset exists.

mixed
offsetGet(mixed $offset)

Get the value at the given offset.

void
offsetSet(mixed $offset, mixed $value)

Set the value at a given offset.

void
offsetUnset(mixed $offset)

Remove the value at the given offset.

getIterator()

Get an iterator for the items.

mixed
jsonSerialize()

Convert the object into a JSON serializable form.

array
toArray()

Get all the attribute values.

string
__toString()

Implode the attributes into a single HTML ready string.

static void
flushState()

Flush all static state.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

at line 44
array all(mixed $keys = null)

Get all the attribute values.

Parameters

mixed $keys

Return Value

array

at line 72
protected mixed data(string|null $key = null, mixed $default = null)

Retrieve data from the instance.

Parameters

string|null $key
mixed $default

Return Value

mixed

in InteractsWithData at line 40
bool exists(array|string $key)

Determine if the data contains a given key.

Parameters

array|string $key

Return Value

bool

in InteractsWithData at line 48
bool has(array|string $key)

Determine if the data contains a given key.

Parameters

array|string $key

Return Value

bool

in InteractsWithData at line 66
bool hasAny(array|string $keys)

Determine if the instance contains any of the given keys.

Parameters

array|string $keys

Return Value

bool

in InteractsWithData at line 80
mixed whenHas(string $key, callable $callback, callable|null $default = null)

Apply the callback if the instance contains the given key.

Parameters

string $key
callable $callback
callable|null $default

Return Value

mixed

in InteractsWithData at line 96
bool filled(array|string $key)

Determine if the instance contains a non-empty value for the given key.

Parameters

array|string $key

Return Value

bool

in InteractsWithData at line 112
bool isNotFilled(array|string $key)

Determine if the instance contains an empty value for the given key.

Parameters

array|string $key

Return Value

bool

in InteractsWithData at line 128
bool anyFilled(array|string $keys)

Determine if the instance contains a non-empty value for any of the given keys.

Parameters

array|string $keys

Return Value

bool

in InteractsWithData at line 146
mixed whenFilled(string $key, callable $callback, callable|null $default = null)

Apply the callback if the instance contains a non-empty value for the given key.

Parameters

string $key
callable $callback
callable|null $default

Return Value

mixed

in InteractsWithData at line 168
mixed whenEnum(string $key, string $enumClass, callable $callback, callable|null $default = null)

Apply the callback if the instance contains a valid enum value for the given key.

Parameters

string $key
string $enumClass
callable $callback
callable|null $default

Return Value

mixed

in InteractsWithData at line 188
bool missing(array|string $key)

Determine if the instance is missing a given key.

Parameters

array|string $key

Return Value

bool

in InteractsWithData at line 198
mixed whenMissing(string $key, callable $callback, callable|null $default = null)

Apply the callback if the instance is missing the given key.

Parameters

string $key
callable $callback
callable|null $default

Return Value

mixed

in InteractsWithData at line 214
protected bool isEmptyString(string $key)

Determine if the given key is an empty string for "filled".

Parameters

string $key

Return Value

bool

in InteractsWithData at line 224
Stringable str(string $key, mixed $default = null)

Retrieve data from the instance as a Stringable instance.

Parameters

string $key
mixed $default

Return Value

Stringable

in InteractsWithData at line 232
Stringable string(string $key, mixed $default = null)

Retrieve data from the instance as a Stringable instance.

Parameters

string $key
mixed $default

Return Value

Stringable

in InteractsWithData at line 242
bool boolean(string|null $key = null, bool $default = false)

Retrieve data as a boolean value.

Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.

Parameters

string|null $key
bool $default

Return Value

bool

in InteractsWithData at line 250
int integer(string $key, int $default = 0)

Retrieve data as an integer value.

Parameters

string $key
int $default

Return Value

int

in InteractsWithData at line 258
float float(string $key, float $default = 0.0)

Retrieve data as a float value.

Parameters

string $key
float $default

Return Value

float

in InteractsWithData at line 266
int|float clamp(string $key, int|float $min, int|float $max, int|float $default = 0)

Retrieve data clamped between min and max values.

Parameters

string $key
int|float $min
int|float $max
int|float $default

Return Value

int|float

in InteractsWithData at line 283
CarbonInterface|null date(string $key, string|null $format = null, UnitEnum|string|null $tz = null)

Retrieve data from the instance as a Carbon instance.

Parameters

string $key
string|null $format
UnitEnum|string|null $tz

Return Value

CarbonInterface|null

Exceptions

InvalidFormatException

in InteractsWithData at line 301
CarbonInterval|null interval(string $key, Unit|string|null $unit = null)

Retrieve data from the instance as a CarbonInterval instance.

Parameters

string $key
Unit|string|null $unit

Return Value

CarbonInterval|null

in InteractsWithData at line 327
mixed enum(string $key, string $enumClass, mixed $default = null)

Retrieve data from the instance as an enum.

Parameters

string $key
string $enumClass
mixed $default

Return Value

mixed

in InteractsWithData at line 350
array enums(string $key, string $enumClass)

Retrieve data from the instance as an array of enums.

Parameters

string $key
string $enumClass

Return Value

array

in InteractsWithData at line 369
protected bool isBackedEnum(string $enumClass)

Determine if the given enum class is backed.

Parameters

string $enumClass

Return Value

bool

in InteractsWithData at line 377
protected int|string|null normalizeEnumValue(string $enumClass, mixed $value)

Normalize enum input to a strict backed value.

Parameters

string $enumClass
mixed $value

Return Value

int|string|null

in InteractsWithData at line 422
protected string|null enumBackingType(string $enumClass)

Resolve and cache the enum backing type for repeated lookups.

Parameters

string $enumClass

Return Value

string|null

at line 84
array array(array|string|null $key = null)

Retrieve data from the instance as an array.

Parameters

array|string|null $key

Return Value

array

in InteractsWithData at line 441
Collection collect(array|string|null $key = null)

Retrieve data from the instance as a collection.

Parameters

array|string|null $key

Return Value

Collection

at line 92
ComponentAttributeBag only(mixed $keys)

Only include the given attribute from the attribute array.

Parameters

mixed $keys

Return Value

ComponentAttributeBag

at line 108
ComponentAttributeBag except(mixed $keys)

Exclude the given attribute from the attribute array.

Parameters

mixed $keys

Return Value

ComponentAttributeBag

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 36
__construct(array $attributes = [])

Create a new component attribute bag instance.

Parameters

array $attributes

at line 56
mixed first(mixed $default = null)

Get the first attribute's value.

Parameters

mixed $default

Return Value

mixed

at line 64
mixed get(string $key, mixed $default = null)

Get a given attribute from the attribute array.

Parameters

string $key
mixed $default

Return Value

mixed

at line 124
ComponentAttributeBag filter(callable $callback)

Filter the attributes, returning a bag of attributes that pass the filter.

Parameters

callable $callback

Return Value

ComponentAttributeBag

at line 134
ComponentAttributeBag whereStartsWith(string|array $needles)

Return a bag of attributes that have keys starting with the given value / pattern.

Parameters

string|array $needles

Return Value

ComponentAttributeBag

at line 146
ComponentAttributeBag whereDoesntStartWith(string|array $needles)

Return a bag of attributes with keys that do not start with the given value / pattern.

Parameters

string|array $needles

Return Value

ComponentAttributeBag

at line 158
ComponentAttributeBag thatStartWith(string|array $needles)

Return a bag of attributes that have keys starting with the given value / pattern.

Parameters

string|array $needles

Return Value

ComponentAttributeBag

at line 166
ComponentAttributeBag onlyProps(mixed $keys)

Only include the given attribute from the attribute array.

Parameters

mixed $keys

Return Value

ComponentAttributeBag

at line 174
ComponentAttributeBag exceptProps(mixed $keys)

Exclude the given attribute from the attribute array.

Parameters

mixed $keys

Return Value

ComponentAttributeBag

at line 182
ComponentAttributeBag class(mixed $classList)

Conditionally merge classes into the attribute bag.

Parameters

mixed $classList

Return Value

ComponentAttributeBag

at line 192
ComponentAttributeBag style(mixed $styleList)

Conditionally merge styles into the attribute bag.

Parameters

mixed $styleList

Return Value

ComponentAttributeBag

at line 202
ComponentAttributeBag merge(array $attributeDefaults = [], bool $escape = true)

Merge additional attributes / values into the attribute bag.

Parameters

array $attributeDefaults
bool $escape

Return Value

ComponentAttributeBag

at line 236
protected bool shouldEscapeAttributeValue(bool $escape, mixed $value)

Determine if the specific attribute value should be escaped.

Parameters

bool $escape
mixed $value

Return Value

bool

at line 250
AppendableAttributeValue prepends(mixed $value)

Create a new appendable attribute value.

Parameters

mixed $value

Return Value

AppendableAttributeValue

at line 258
protected mixed resolveAppendableAttributeDefault(array $attributeDefaults, string $key, bool $escape)

Resolve an appendable attribute value default value.

Parameters

array $attributeDefaults
string $key
bool $escape

Return Value

mixed

at line 270
bool isEmpty()

Determine if the attribute bag is empty.

Return Value

bool

at line 278
bool isNotEmpty()

Determine if the attribute bag is not empty.

Return Value

bool

at line 286
array getAttributes()

Get all of the raw attributes.

Return Value

array

at line 294
void setAttributes(array $attributes)

Set the underlying attributes.

Parameters

array $attributes

Return Value

void

at line 311
static array extractPropNames(array $keys)

Extract "prop" names from given keys.

Parameters

array $keys

Return Value

array

at line 328
string toHtml()

Get content as a string of HTML.

Return Value

string

at line 336
HtmlString __invoke(array $attributeDefaults = [])

Merge additional attributes / values into the attribute bag.

Parameters

array $attributeDefaults

Return Value

HtmlString

at line 344
bool offsetExists(mixed $offset)

Determine if the given offset exists.

Parameters

mixed $offset

Return Value

bool

at line 352
mixed offsetGet(mixed $offset)

Get the value at the given offset.

Parameters

mixed $offset

Return Value

mixed

at line 360
void offsetSet(mixed $offset, mixed $value)

Set the value at a given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

at line 368
void offsetUnset(mixed $offset)

Remove the value at the given offset.

Parameters

mixed $offset

Return Value

void

at line 376
ArrayIterator getIterator()

Get an iterator for the items.

Return Value

ArrayIterator

at line 384
mixed jsonSerialize()

Convert the object into a JSON serializable form.

Return Value

mixed

at line 392
array toArray()

Get all the attribute values.

Return Value

array

at line 400
string __toString()

Implode the attributes into a single HTML ready string.

Return Value

string

at line 422
static void flushState()

Flush all static state.

Return Value

void