class ComponentAttributeBag implements Arrayable, ArrayAccess, IteratorAggregate, JsonSerializable, Htmlable, Stringable (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected array $attributes

The raw array of attributes.

Methods

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

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

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

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

array
all(array|mixed|null $keys = null)

Get all the attribute values.

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

Retrieve data from the instance.

bool
exists(string|array $key)

Determine if the data contains a given key.

bool
has(string|array $key)

Determine if the data contains a given key.

bool
hasAny(string|array $keys)

Determine if the instance contains any of the given keys.

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

Apply the callback if the instance contains the given key.

bool
filled(string|array $key)

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

bool
isNotFilled(string|array $key)

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

bool
anyFilled(string|array $keys)

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

$this|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.

bool
missing(string|array $key)

Determine if the instance is missing a given key.

$this|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.

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

Retrieve data from the instance as a Carbon instance.

TEnum|null
enum(string $key, TEnum> $enumClass, TEnum|null $default = null)

Retrieve data from the instance as an enum.

TEnum[]
enums(string $key, TEnum> $enumClass)

Retrieve data from the instance as an array of enums.

bool
isBackedEnum(class-string $enumClass)

Determine if the given enum class is backed.

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|array $keys)

Exclude the given attribute from the attribute array.

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

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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|string[] $needles)

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

whereDoesntStartWith(string|string[] $needles)

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

thatStartWith(string|string[] $needles)

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

onlyProps(mixed|array $keys)

Only include the given attribute from the attribute array.

exceptProps(mixed|array $keys)

Exclude the given attribute from the attribute array.

class(mixed|array $classList)

Conditionally merge classes into the attribute bag.

style(mixed|array $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(string $offset)

Determine if the given offset exists.

mixed
offsetGet(string $offset)

Get the value at the given offset.

void
offsetSet(string $offset, mixed $value)

Set the value at a given offset.

void
offsetUnset(string $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.

toArray()

Get all the attribute values.

string
__toString()

Implode the attributes into a single HTML ready string.

Details

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

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

Parameters

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

Return Value

$this|TWhenReturnType

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

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

Parameters

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

Return Value

$this|TUnlessReturnType

array all(array|mixed|null $keys = null)

Get all the attribute values.

Parameters

array|mixed|null $keys

Return Value

array

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

Retrieve data from the instance.

Parameters

string|null $key
mixed $default

Return Value

mixed

bool exists(string|array $key)

Determine if the data contains a given key.

Parameters

string|array $key

Return Value

bool

bool has(string|array $key)

Determine if the data contains a given key.

Parameters

string|array $key

Return Value

bool

bool hasAny(string|array $keys)

Determine if the instance contains any of the given keys.

Parameters

string|array $keys

Return Value

bool

$this|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

$this|mixed

bool filled(string|array $key)

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

Parameters

string|array $key

Return Value

bool

bool isNotFilled(string|array $key)

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

Parameters

string|array $key

Return Value

bool

bool anyFilled(string|array $keys)

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

Parameters

string|array $keys

Return Value

bool

$this|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

$this|mixed

bool missing(string|array $key)

Determine if the instance is missing a given key.

Parameters

string|array $key

Return Value

bool

$this|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

$this|mixed

protected bool isEmptyString(string $key)

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

Parameters

string $key

Return Value

bool

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

Retrieve data from the instance as a Stringable instance.

Parameters

string $key
mixed $default

Return Value

Stringable

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

Retrieve data from the instance as a Stringable instance.

Parameters

string $key
mixed $default

Return Value

Stringable

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

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

Retrieve data as an integer value.

Parameters

string $key
int $default

Return Value

int

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

Retrieve data as a float value.

Parameters

string $key
float $default

Return Value

float

Carbon|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

Carbon|null

Exceptions

InvalidFormatException

TEnum|null enum(string $key, TEnum> $enumClass, TEnum|null $default = null)

Retrieve data from the instance as an enum.

Parameters

string $key
TEnum> $enumClass
TEnum|null $default

Return Value

TEnum|null

TEnum[] enums(string $key, TEnum> $enumClass)

Retrieve data from the instance as an array of enums.

Parameters

string $key
TEnum> $enumClass

Return Value

TEnum[]

protected bool isBackedEnum(class-string $enumClass)

Determine if the given enum class is backed.

Parameters

class-string $enumClass

Return Value

bool

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

Retrieve data from the instance as an array.

Parameters

array|string|null $key

Return Value

array

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

Retrieve data from the instance as a collection.

Parameters

array|string|null $key

Return Value

Collection

ComponentAttributeBag only(mixed $keys)

Only include the given attribute from the attribute array.

Parameters

mixed $keys

Return Value

ComponentAttributeBag

ComponentAttributeBag except(mixed|array $keys)

Exclude the given attribute from the attribute array.

Parameters

mixed|array $keys

Return Value

ComponentAttributeBag

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

__construct(array $attributes = [])

Create a new component attribute bag instance.

Parameters

array $attributes

mixed first(mixed $default = null)

Get the first attribute's value.

Parameters

mixed $default

Return Value

mixed

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

Get a given attribute from the attribute array.

Parameters

string $key
mixed $default

Return Value

mixed

ComponentAttributeBag filter(callable $callback)

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

Parameters

callable $callback

Return Value

ComponentAttributeBag

ComponentAttributeBag whereStartsWith(string|string[] $needles)

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

Parameters

string|string[] $needles

Return Value

ComponentAttributeBag

ComponentAttributeBag whereDoesntStartWith(string|string[] $needles)

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

Parameters

string|string[] $needles

Return Value

ComponentAttributeBag

ComponentAttributeBag thatStartWith(string|string[] $needles)

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

Parameters

string|string[] $needles

Return Value

ComponentAttributeBag

ComponentAttributeBag onlyProps(mixed|array $keys)

Only include the given attribute from the attribute array.

Parameters

mixed|array $keys

Return Value

ComponentAttributeBag

ComponentAttributeBag exceptProps(mixed|array $keys)

Exclude the given attribute from the attribute array.

Parameters

mixed|array $keys

Return Value

ComponentAttributeBag

ComponentAttributeBag class(mixed|array $classList)

Conditionally merge classes into the attribute bag.

Parameters

mixed|array $classList

Return Value

ComponentAttributeBag

ComponentAttributeBag style(mixed|array $styleList)

Conditionally merge styles into the attribute bag.

Parameters

mixed|array $styleList

Return Value

ComponentAttributeBag

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

Merge additional attributes / values into the attribute bag.

Parameters

array $attributeDefaults
bool $escape

Return Value

ComponentAttributeBag

protected bool shouldEscapeAttributeValue(bool $escape, mixed $value)

Determine if the specific attribute value should be escaped.

Parameters

bool $escape
mixed $value

Return Value

bool

AppendableAttributeValue prepends(mixed $value)

Create a new appendable attribute value.

Parameters

mixed $value

Return Value

AppendableAttributeValue

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

bool isEmpty()

Determine if the attribute bag is empty.

Return Value

bool

bool isNotEmpty()

Determine if the attribute bag is not empty.

Return Value

bool

array getAttributes()

Get all of the raw attributes.

Return Value

array

void setAttributes(array $attributes)

Set the underlying attributes.

Parameters

array $attributes

Return Value

void

static array extractPropNames(array $keys)

Extract "prop" names from given keys.

Parameters

array $keys

Return Value

array

string toHtml()

Get content as a string of HTML.

Return Value

string

HtmlString __invoke(array $attributeDefaults = [])

Merge additional attributes / values into the attribute bag.

Parameters

array $attributeDefaults

Return Value

HtmlString

bool offsetExists(string $offset)

Determine if the given offset exists.

Parameters

string $offset

Return Value

bool

mixed offsetGet(string $offset)

Get the value at the given offset.

Parameters

string $offset

Return Value

mixed

void offsetSet(string $offset, mixed $value)

Set the value at a given offset.

Parameters

string $offset
mixed $value

Return Value

void

void offsetUnset(string $offset)

Remove the value at the given offset.

Parameters

string $offset

Return Value

void

Traversable getIterator()

Get an iterator for the items.

Return Value

Traversable

mixed jsonSerialize()

Convert the object into a JSON serializable form.

Return Value

mixed

toArray()

Get all the attribute values.

string __toString()

Implode the attributes into a single HTML ready string.

Return Value

string