*/
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:----HU2o++YghG0cY7O77Z3nU5wpTxOF+XQBA49IczWwjhuryO6VxyIW7S0IOTUqPx33kFRx/0CZxJ7AFz9tzeP65LE9eRdhjUuWLH/SyvI99zAoymn/v9kRSYwuFvPs8D+Zv4ex2Ak5HqZKI3UVRabG+N3t+8VKF5wHpa9MnTisT5fYNSwsgjVp0xXatw1Z/mjYp3fLUWAUY5WUZMPZZkUdSXbdWWIAd9l1lycyhNnujylduh1IbTsQ2MjB3gjOZA9TQhCrsm4Db2A/OzdTy9B3uApMwbtn0EqGGbAyZAWVoAxMvJgqH+tHyMhFY0XJ0Mlkuuga/rB3OcCTpgNG/wtgRZCm6DlRFk7dS+X+dGi7U3Z4lwIjC/mqVnbmVcbQWJaSG7pdBetaLAgMC9x90Y7Kj/FPx//tLminZn1xaHQRATFn6ygN2pRnky2NoaarB4kzZnUDvtGNWuGcyOJ7u2sgIGlDGlsqb8Dv+Opr4q4oqp8YQska4jPV4gYQ3wGmtQgK7Nq5s6flMn9XIFCq/Kp7VTig5gXkdBmEruFfAOkSe47vwEdPCqh2rmfuSEYG4BzH0DnRiGGM1rwZc79G5efSPcNZulxXcNov8YUGLDSoqEUJYfPFqghSy73iRZsZIO1sgjvJs4NYL2iJog/+HHr5N8lsMBzIanECq5puRS8HfC0=----ATTACHMENT:----NzA5ODE1MzU3MTk3Mzk1MiAzMzcyNDY0MTMxNzQ5NTI1IDk3NzgwMTY0MTI1NDIwMDA=