mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Fill in union context
This commit is contained in:
parent
0c8f33c37c
commit
206c5c0012
3 changed files with 43 additions and 3 deletions
|
@ -6,8 +6,7 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
namespace JKingWeb\Arsse\Context;
|
namespace JKingWeb\Arsse\Context;
|
||||||
|
|
||||||
class Context extends AbstractContext {
|
class Context extends RootContext {
|
||||||
use RootMembers;
|
|
||||||
use BooleanMembers;
|
use BooleanMembers;
|
||||||
use ExclusionMembers;
|
use ExclusionMembers;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
namespace JKingWeb\Arsse\Context;
|
namespace JKingWeb\Arsse\Context;
|
||||||
|
|
||||||
trait RootMembers {
|
class RootContext extends AbstractContext {
|
||||||
public $limit = 0;
|
public $limit = 0;
|
||||||
public $offset = 0;
|
public $offset = 0;
|
||||||
|
|
41
lib/Context/UnionContext.php
Normal file
41
lib/Context/UnionContext.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?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 {
|
||||||
|
return array_key_exists($offset, $this->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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue