Archived
1
0
Fork 0
This repository has been archived on 2026-06-16. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
wow-raid-bingo/app/Support/Set.php
2021-10-18 11:56:52 +02:00

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;
}
}