Make exclusion contexts return their parent on change
This commit is contained in:
parent
b950ac066f
commit
18d52ea402
3 changed files with 26 additions and 2 deletions
|
@ -27,7 +27,7 @@ class Context extends ExclusionContext {
|
|||
public $notMarkedSince;
|
||||
|
||||
public function __construct() {
|
||||
$this->not = new ExclusionContext;
|
||||
$this->not = new ExclusionContext($this);
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
|
@ -35,6 +35,10 @@ class Context extends ExclusionContext {
|
|||
$this->not = clone $this->not;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
unset($this->not);
|
||||
}
|
||||
|
||||
public function reverse(bool $spec = null) {
|
||||
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,24 @@ class ExclusionContext {
|
|||
public $authorTerms;
|
||||
|
||||
protected $props = [];
|
||||
protected $parent;
|
||||
|
||||
public function __construct(self $c = null) {
|
||||
$this->parent = $c;
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
if ($this->parent) {
|
||||
$p = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT, 2)[1]['object'] ?? null;
|
||||
if ($p instanceof self) {
|
||||
$this->parent = $p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
unset($this->parent);
|
||||
}
|
||||
|
||||
protected function act(string $prop, int $set, $value) {
|
||||
if ($set) {
|
||||
|
@ -34,7 +52,7 @@ class ExclusionContext {
|
|||
$this->props[$prop] = true;
|
||||
$this->$prop = $value;
|
||||
}
|
||||
return $this;
|
||||
return $this->parent ?? $this;
|
||||
} else {
|
||||
return isset($this->props[$prop]);
|
||||
}
|
||||
|
|
|
@ -104,5 +104,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
$this->assertEquals($c1->not, $c2->not);
|
||||
$this->assertNotSame($c1, $c2);
|
||||
$this->assertNotSame($c1->not, $c2->not);
|
||||
$this->assertSame($c1, $c1->not->article(null));
|
||||
$this->assertSame($c2, $c2->not->article(null));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue