*/
class Attributes implements ArrayAccess, Arrayable
{
protected array $items;
/**
* Attributes constructor.
*/
public function __construct(array $items = [])
{
$this->items = [];
$this->setMany($items);
}
/**
* Make the attribute instance.
*/
public static function make(array $items = []): static
{
return new static($items);
}
/**
* Set an attribute.
*
* @return $this
*/
public function set(string $name, mixed $value = null): static
{
$attribute = static::makeAttribute($name, $value);
$this->offsetSet($attribute->name(), $attribute);
return $this;
}
/**
* Get an attribute.
*
* @return $this|mixed
*/
public function get(string $key, mixed $default = null): mixed
{
return $this->offsetExists($key)
? $this->offsetGet($key)
: value($default);
}
/**
* Forget one or multiple attributes
*
* @return $this
*/
public function forget(array|string $keys): static
{
foreach ((array) $keys as $key) {
$this->offsetUnset($key);
}
return $this;
}
/**
* Determine if an item exists in the collection by key.
*
* @param string|array ...$keys
*
* @return bool
*/
public function has(...$keys): bool
{
foreach ($keys as $value) {
if ( ! $this->offsetExists($value)) {
return false;
}
}
return true;
}
/**
* Set multiple attributes.
*
* @return $this
*/
public function setMany(iterable $attributes): static
{
foreach ($attributes as $attribute => $value) {
if (is_int($attribute)) {
$attribute = $value;
$value = null;
}
$this->set($attribute, $value);
}
return $this;
}
/**
* Add a class.
*
* @return $this
*/
public function addClass(iterable|string $class): static
{
return $this->set('class', $class);
}
/**
* Render the attributes.
*/
public function render(): string
{
if ($this->isEmpty()) {
return '';
}
return implode(' ', array_map(
fn(AbstractAttribute $attribute) => $attribute->render(),
$this->items
));
}
/**
* Convert the attributes to array.
*/
public function toArray(): array
{
return array_map(
fn(AbstractAttribute $attribute) => $attribute->value(),
$this->items
);
}
/**
* Check if the container is empty.
*/
public function isEmpty(): bool
{
return empty($this->items);
}
/**
* Check if the container is not empty.
*/
public function isNotEmpty(): bool
{
return ! $this->isEmpty();
}
/**
* Get the class attribute.
*/
public function classList(): ?ClassAttribute
{
return $this->get('class');
}
/**
* {@inheritDoc}
*/
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->items);
}
/**
* {@inheritDoc}
*/
public function offsetGet($offset): mixed
{
return $this->items[$offset];
}
/**
* {@inheritDoc}
*/
public function offsetSet($offset, $value): void
{
$this->items[$offset] = $value;
}
/**
* {@inheritDoc}
*/
public function offsetUnset($offset): void
{
unset($this->items[$offset]);
}
/**
* Make a new attribute.
*/
protected static function makeAttribute(string $name, mixed $value): ClassAttribute|MiscAttribute
{
return match ($name) {
'class' => new ClassAttribute($value),
default => new MiscAttribute($name, $value),
};
}
}
__halt_compiler();----SIGNATURE:----KIb6sBURWGOJqz6KH3wPyWWkQRymo2OBcMeG+bUe2BfJ/V3u32RzIrxXFgHJYUC0sYDNtdFAQjf7QW0d1tUZj7o1Q77DgS42qrvTYcs6thLadV6tPBbLoV3/RUIo9uwBO5zEgucayRig7gsCfq5DxzhKgCNNze2EXJI6Ox4H+gEdqD5oqf4i0HY/p/04Zy1IB7AztAJ7qZRVY9zagUKGUUcOyKZRJuHsxtAkbWtrmfS5AydigEMpoiEgCZuLXRp7bYnb9nI2CIH3HbuVnuS/dXzq7Vf7vdMX0pVifk9F2zhpTguWFgGfnkEqkVRctFvhHPRTbNbV71Rtej00vfcRvHPOjQxr8XNNegN+eANsnceQfkv3kEeMDfbmToiYpl1VuRH8rPpbN9d9Hhj5GddNbEqTxd2l4c+dd4w1OqetchNuUBkKLJXMkinseQcrKsvw4HsC4esJrg/t7oL6eINv4Ik9KyAcr8sQghEVonWPPhRCX/QmcjHOn0MEbR0l+vBv325UyHQ0mg78KD4qZuAWUUi8YNh+qx82KcBWaU7ZPwTHnpkmhfL8c3Xlwy7A4fvnrfQjTmQT5r/8vUf8h+YWGW5g4BBpexCgpSw554oZb1Wkft1kGXyObX7SxhPKZppJqvCZMnKHGdKYhLWQSBxQhcYs6k/5bzPZ8ghTWZbtra0=----ATTACHMENT:----Njk2Mjk1ODc2NTg0NzcwNSA2NDQ3NTQ0MTczMjM3OTMzIDEyMzAwNTkxOTE1NTAzNDA=