From 206c5c0012888f7eca08d907311275056f814ad6 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 28 Apr 2022 22:32:10 -0400 Subject: [PATCH] Fill in union context --- lib/Context/Context.php | 3 +- .../{RootMembers.php => RootContext.php} | 2 +- lib/Context/UnionContext.php | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) rename lib/Context/{RootMembers.php => RootContext.php} (91%) create mode 100644 lib/Context/UnionContext.php diff --git a/lib/Context/Context.php b/lib/Context/Context.php index e7cdc89..4ab9595 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 d5048b2..950a867 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 0000000..257e501 --- /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; + } +}