2017-04-18 05:44:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Stripe\Util;
|
|
|
|
|
|
|
|
|
|
use ArrayIterator;
|
2021-01-03 23:37:44 +01:00
|
|
|
use IteratorAggregate;
|
2017-04-18 05:44:08 +02:00
|
|
|
|
|
|
|
|
class Set implements IteratorAggregate
|
|
|
|
|
{
|
|
|
|
|
private $_elts;
|
|
|
|
|
|
2018-03-07 19:25:05 +01:00
|
|
|
public function __construct($members = [])
|
2017-04-18 05:44:08 +02:00
|
|
|
{
|
2018-03-07 19:25:05 +01:00
|
|
|
$this->_elts = [];
|
2017-04-18 05:44:08 +02:00
|
|
|
foreach ($members as $item) {
|
|
|
|
|
$this->_elts[$item] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function includes($elt)
|
|
|
|
|
{
|
|
|
|
|
return isset($this->_elts[$elt]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function add($elt)
|
|
|
|
|
{
|
|
|
|
|
$this->_elts[$elt] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function discard($elt)
|
|
|
|
|
{
|
|
|
|
|
unset($this->_elts[$elt]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toArray()
|
|
|
|
|
{
|
2021-01-03 23:37:44 +01:00
|
|
|
return \array_keys($this->_elts);
|
2017-04-18 05:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-24 18:42:04 +02:00
|
|
|
/**
|
|
|
|
|
* @return ArrayIterator
|
|
|
|
|
*/
|
|
|
|
|
#[\ReturnTypeWillChange]
|
2017-04-18 05:44:08 +02:00
|
|
|
public function getIterator()
|
|
|
|
|
{
|
|
|
|
|
return new ArrayIterator($this->toArray());
|
|
|
|
|
}
|
|
|
|
|
}
|