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; + } +}