ComponentAttributeBag
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
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Get all the attribute values.
Retrieve data from the instance.
Determine if the instance contains any of the given keys.
Apply the callback if the instance contains the given key.
Determine if the instance contains a non-empty value for the given key.
Determine if the instance contains an empty value for the given key.
Determine if the instance contains a non-empty value for any of the given keys.
Apply the callback if the instance contains a non-empty value for the given key.
Apply the callback if the instance contains a valid enum value for the given key.
Determine if the instance is missing a given key.
Apply the callback if the instance is missing the given key.
Determine if the given key is an empty string for "filled".
Retrieve data from the instance as a Stringable instance.
Retrieve data from the instance as a Stringable instance.
Retrieve data as a boolean value.
Retrieve data as an integer value.
Retrieve data as a float value.
Retrieve data clamped between min and max values.
Retrieve data from the instance as a Carbon instance.
Retrieve data from the instance as a CarbonInterval instance.
Retrieve data from the instance as an enum.
Retrieve data from the instance as an array of enums.
Retrieve data from the instance as an array.
Retrieve data from the instance as a collection.
Only include the given attribute from the attribute array.
Exclude the given attribute from the attribute array.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new component attribute bag instance.
Get the first attribute's value.
Get a given attribute from the attribute array.
Filter the attributes, returning a bag of attributes that pass the filter.
Return a bag of attributes that have keys starting with the given value / pattern.
Return a bag of attributes with keys that do not start with the given value / pattern.
Return a bag of attributes that have keys starting with the given value / pattern.
Only include the given attribute from the attribute array.
Exclude the given attribute from the attribute array.
Conditionally merge classes into the attribute bag.
Conditionally merge styles into the attribute bag.
Merge additional attributes / values into the attribute bag.
Determine if the specific attribute value should be escaped.
Create a new appendable attribute value.
Resolve an appendable attribute value default value.
Determine if the attribute bag is empty.
Determine if the attribute bag is not empty.
Get all of the raw attributes.
Set the underlying attributes.
Extract "prop" names from given keys.
Get content as a string of HTML.
Merge additional attributes / values into the attribute bag.
Determine if the given offset exists.
Get the value at the given offset.
Set the value at a given offset.
Remove the value at the given offset.
Get an iterator for the items.
Convert the object into a JSON serializable form.
Get all the attribute values.
Implode the attributes into a single HTML ready string.
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.
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.
at line 44
array
all(mixed $keys = null)
Get all the attribute values.
at line 74
protected mixed
data(string|null $key = null, mixed $default = null)
Retrieve data from the instance.
in
InteractsWithData at line 40
bool
exists(array|string $key)
Determine if the data contains a given key.
in
InteractsWithData at line 48
bool
has(array|string $key)
Determine if the data contains a given key.
in
InteractsWithData at line 67
bool
hasAny(array|string $keys)
Determine if the instance contains any of the given keys.
in
InteractsWithData at line 86
mixed
whenHas(string $key, callable $callback, callable|null $default = null)
Apply the callback if the instance contains the given key.
in
InteractsWithData at line 102
bool
filled(array|string $key)
Determine if the instance contains a non-empty value for the given key.
in
InteractsWithData at line 119
bool
isNotFilled(array|string $key)
Determine if the instance contains an empty value for the given key.
in
InteractsWithData at line 136
bool
anyFilled(array|string $keys)
Determine if the instance contains a non-empty value for any of the given keys.
in
InteractsWithData at line 160
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.
in
InteractsWithData at line 185
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.
in
InteractsWithData at line 201
bool
missing(array|string $key)
Determine if the instance is missing a given key.
in
InteractsWithData at line 218
mixed
whenMissing(string $key, callable $callback, callable|null $default = null)
Apply the callback if the instance is missing the given key.
in
InteractsWithData at line 234
protected bool
isEmptyString(string $key)
Determine if the given key is an empty string for "filled".
in
InteractsWithData at line 246
Stringable
str(string $key, mixed $default = null, bool $strict = false)
Retrieve data from the instance as a Stringable instance.
in
InteractsWithData at line 256
Stringable
string(string $key, mixed $default = null, bool $strict = false)
Retrieve data from the instance as a Stringable instance.
When strict, values that are not strings, numbers, or Stringable objects return the default.
in
InteractsWithData at line 279
bool|null
boolean(string|null $key = null, Closure|bool|null $default = false, bool $strict = false)
Retrieve data as a boolean value.
Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false. When strict, unrecognized or empty values return the default.
in
InteractsWithData at line 301
int|null
integer(string $key, Closure|int|null $default = 0, bool $strict = false)
Retrieve data as an integer value.
When strict, values that are not valid integers return the default.
in
InteractsWithData at line 328
float|null
float(string $key, Closure|float|null $default = 0.0, bool $strict = false)
Retrieve data as a float value.
When strict, values that are not valid numbers return the default.
in
InteractsWithData at line 347
int|float
clamp(string $key, int|float $min, int|float $max, int|float $default = 0)
Retrieve data clamped between min and max values.
in
InteractsWithData at line 365
CarbonInterface|null
date(string $key, string|null $format = null, UnitEnum|string|null $tz = null)
Retrieve data from the instance as a Carbon instance.
in
InteractsWithData at line 383
CarbonInterval|null
interval(string $key, Unit|string|null $unit = null)
Retrieve data from the instance as a CarbonInterval instance.
in
InteractsWithData at line 410
mixed
enum(string $key, string $enumClass, mixed $default = null)
Retrieve data from the instance as an enum.
in
InteractsWithData at line 427
array
enums(string $key, string $enumClass)
Retrieve data from the instance as an array of enums.
in
InteractsWithData at line 442
array
array(array|string|null $key = null)
Retrieve data from the instance as an array.
in
InteractsWithData at line 452
Collection
collect(array|string|null $key = null)
Retrieve data from the instance as a collection.
at line 86
ComponentAttributeBag
only(mixed $keys)
Only include the given attribute from the attribute array.
at line 102
ComponentAttributeBag
except(mixed $keys)
Exclude the given attribute from the attribute array.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 36
__construct(array $attributes = [])
Create a new component attribute bag instance.
at line 56
mixed
first(mixed $default = null)
Get the first attribute's value.
at line 64
mixed
get(string $key, mixed $default = null)
Get a given attribute from the attribute array.
at line 118
ComponentAttributeBag
filter(callable $callback)
Filter the attributes, returning a bag of attributes that pass the filter.
at line 128
ComponentAttributeBag
whereStartsWith(string|array $needles)
Return a bag of attributes that have keys starting with the given value / pattern.
at line 140
ComponentAttributeBag
whereDoesntStartWith(string|array $needles)
Return a bag of attributes with keys that do not start with the given value / pattern.
at line 152
ComponentAttributeBag
thatStartWith(string|array $needles)
Return a bag of attributes that have keys starting with the given value / pattern.
at line 160
ComponentAttributeBag
onlyProps(mixed $keys)
Only include the given attribute from the attribute array.
at line 168
ComponentAttributeBag
exceptProps(mixed $keys)
Exclude the given attribute from the attribute array.
at line 176
ComponentAttributeBag
class(mixed $classList)
Conditionally merge classes into the attribute bag.
at line 186
ComponentAttributeBag
style(mixed $styleList)
Conditionally merge styles into the attribute bag.
at line 196
ComponentAttributeBag
merge(array $attributeDefaults = [], bool $escape = true)
Merge additional attributes / values into the attribute bag.
at line 234
protected bool
shouldEscapeAttributeValue(bool $escape, mixed $value)
Determine if the specific attribute value should be escaped.
at line 248
AppendableAttributeValue
prepends(mixed $value)
Create a new appendable attribute value.
at line 256
protected mixed
resolveAppendableAttributeDefault(array $attributeDefaults, string $key, bool $escape)
Resolve an appendable attribute value default value.
at line 268
bool
isEmpty()
Determine if the attribute bag is empty.
at line 276
bool
isNotEmpty()
Determine if the attribute bag is not empty.
at line 284
array
getAttributes()
Get all of the raw attributes.
at line 292
void
setAttributes(array $attributes)
Set the underlying attributes.
at line 309
static array
extractPropNames(array $keys)
Extract "prop" names from given keys.
at line 326
string
toHtml()
Get content as a string of HTML.
at line 334
HtmlString
__invoke(array $attributeDefaults = [])
Merge additional attributes / values into the attribute bag.
at line 342
bool
offsetExists(mixed $offset)
Determine if the given offset exists.
at line 350
mixed
offsetGet(mixed $offset)
Get the value at the given offset.
at line 358
void
offsetSet(mixed $offset, mixed $value)
Set the value at a given offset.
at line 366
void
offsetUnset(mixed $offset)
Remove the value at the given offset.
at line 374
ArrayIterator
getIterator()
Get an iterator for the items.
at line 382
mixed
jsonSerialize()
Convert the object into a JSON serializable form.
at line 390
array
toArray()
Get all the attribute values.
at line 398
string
__toString()
Implode the attributes into a single HTML ready string.
at line 420
static void
flushState()
Flush all static state.