diff --git a/lib/Context/Context.php b/lib/Context/Context.php index e7cdc894..4ab9595c 100644 --- a/lib/Context/Context.php +++ b/lib/Context/Context.php @@ -6,8 +6,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\Context; -class Context extends AbstractContext { - use RootMembers; +class Context extends RootContext { use BooleanMembers; use ExclusionMembers; diff --git a/lib/Context/RootMembers.php b/lib/Context/RootContext.php similarity index 91% rename from lib/Context/RootMembers.php rename to lib/Context/RootContext.php index d5048b25..950a8670 100644 --- a/lib/Context/RootMembers.php +++ b/lib/Context/RootContext.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\Context; -trait RootMembers { +class RootContext extends AbstractContext { public $limit = 0; public $offset = 0; diff --git a/lib/Context/UnionContext.php b/lib/Context/UnionContext.php new file mode 100644 index 00000000..257e5019 --- /dev/null +++ b/lib/Context/UnionContext.php @@ -0,0 +1,41 @@ +contexts); + } + + public function offsetGet(mixed $offset): mixed { + return $this->contexts[$offset] ?? null; + } + + public function offsetSet(mixed $offset, mixed $value): void { + $this->contexts[$offset ?? count($this->contexts)] = $value; + } + + 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; + } + } + + public function __construct(Context ...$context) { + $this->contexts = $context; + } +}