2022-04-29 02:32:10 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Context;
|
|
|
|
|
|
|
|
class UnionContext extends RootContext implements \ArrayAccess, \Countable, \IteratorAggregate {
|
|
|
|
protected $contexts = [];
|
|
|
|
|
|
|
|
public function offsetExists(mixed $offset): bool {
|
2022-04-29 20:35:46 +00:00
|
|
|
return isset($this->contexts[$offset]);
|
2022-04-29 02:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetGet(mixed $offset): mixed {
|
|
|
|
return $this->contexts[$offset] ?? null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetSet(mixed $offset, mixed $value): void {
|
2022-04-29 20:35:46 +00:00
|
|
|
assert($value instanceof RootContext, new \Exception("Union contexts may only contain other non-exclusion contexts"));
|
|
|
|
if (isset($offset)) {
|
|
|
|
$this->contexts[$offset] = $value;
|
|
|
|
} else {
|
|
|
|
$this->contexts[] = $value;
|
|
|
|
}
|
2022-04-29 02:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetUnset(mixed $offset): void {
|
|
|
|
unset($this->contexts[$offset]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function count(): int {
|
|
|
|
return count($this->contexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIterator(): \Traversable {
|
|
|
|
foreach ($this->contexts as $k => $c) {
|
|
|
|
yield $k => $c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 20:35:46 +00:00
|
|
|
public function __construct(RootContext ...$context) {
|
2022-04-29 02:32:10 +00:00
|
|
|
$this->contexts = $context;
|
|
|
|
}
|
|
|
|
}
|