1
0
Fork 0
wow-raid-bingo/app/Support/Set.php

74 lines
1.2 KiB
PHP

<?php
namespace App\Support;
use Illuminate\Support\Collection;
class Set implements \Countable
{
/**
*
*/
protected $items = [];
public function __construct($items = [])
{
foreach ($items as $k => $v) {
$this->set($k, $v);
}
}
public function set($key, bool $value = true): self
{
if ($value) {
$this->items[$key] = true;
} else {
unset($this->items[$key]);
}
return $this;
}
public function fill($array): self
{
$this->clear();
foreach ($array as $k => $v) {
$this->set($k, $v);
}
return $this;
}
public function has($key): bool
{
return isset($this->items[$key]);
}
public function toggle($key): self
{
$this->set($key, !$this->has($key));
return $this;
}
public function clear(): self
{
$this->items = [];
return $this;
}
public function all(): Collection
{
return collect($this->items)->keys();
}
public function count(): int
{
return count($this->items);
}
public function toArray()
{
return $this->items;
}
}