Archived
1
0
Fork 0

Initial Commit

This commit is contained in:
Henrik Hautakoski 2021-10-18 11:53:33 +02:00
commit ddf09fe00c
113 changed files with 187148 additions and 0 deletions

74
app/Support/Set.php Normal file
View file

@ -0,0 +1,74 @@
<?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;
}
}