1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Make exclusion contexts return their parent on change

This commit is contained in:
J. King 2019-02-25 23:37:14 -05:00
parent b950ac066f
commit 18d52ea402
3 changed files with 26 additions and 2 deletions

View file

@ -27,7 +27,7 @@ class Context extends ExclusionContext {
public $notMarkedSince; public $notMarkedSince;
public function __construct() { public function __construct() {
$this->not = new ExclusionContext; $this->not = new ExclusionContext($this);
} }
public function __clone() { public function __clone() {
@ -35,6 +35,10 @@ class Context extends ExclusionContext {
$this->not = clone $this->not; $this->not = clone $this->not;
} }
public function __destruct() {
unset($this->not);
}
public function reverse(bool $spec = null) { public function reverse(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec); return $this->act(__FUNCTION__, func_num_args(), $spec);
} }

View file

@ -24,6 +24,24 @@ class ExclusionContext {
public $authorTerms; public $authorTerms;
protected $props = []; 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) { protected function act(string $prop, int $set, $value) {
if ($set) { if ($set) {
@ -34,7 +52,7 @@ class ExclusionContext {
$this->props[$prop] = true; $this->props[$prop] = true;
$this->$prop = $value; $this->$prop = $value;
} }
return $this; return $this->parent ?? $this;
} else { } else {
return isset($this->props[$prop]); return isset($this->props[$prop]);
} }

View file

@ -104,5 +104,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertEquals($c1->not, $c2->not); $this->assertEquals($c1->not, $c2->not);
$this->assertNotSame($c1, $c2); $this->assertNotSame($c1, $c2);
$this->assertNotSame($c1->not, $c2->not); $this->assertNotSame($c1->not, $c2->not);
$this->assertSame($c1, $c1->not->article(null));
$this->assertSame($c2, $c2->not->article(null));
} }
} }