diff --git a/lib/Misc/Context.php b/lib/Misc/Context.php index 1dd1a17..9263fa1 100644 --- a/lib/Misc/Context.php +++ b/lib/Misc/Context.php @@ -10,6 +10,7 @@ use JKingWeb\Arsse\Misc\Date; use JKingWeb\Arsse\Misc\ValueInfo; class Context { + public $not = null; public $reverse = false; public $limit = 0; public $offset = 0; @@ -36,9 +37,16 @@ class Context { public $annotated = null; public $annotationTerms = null; public $searchTerms = null; + public $titleTerms = null; + public $authorTerms = null; protected $props = []; + public function __clone() { + // clone the negation context, if any + $this->not = $this->not ? clone $this->not : null; + } + protected function act(string $prop, int $set, $value) { if ($set) { if (is_null($value)) { @@ -198,4 +206,22 @@ class Context { } return $this->act(__FUNCTION__, func_num_args(), $spec); } + + public function titleTerms(array $spec = null) { + if (isset($spec)) { + $spec = $this->cleanStringArray($spec); + } + return $this->act(__FUNCTION__, func_num_args(), $spec); + } + + public function authorTerms(array $spec = null) { + if (isset($spec)) { + $spec = $this->cleanStringArray($spec); + } + return $this->act(__FUNCTION__, func_num_args(), $spec); + } + + public function not(self $spec = null) { + return $this->act(__FUNCTION__, func_num_args(), $spec); + } } diff --git a/tests/cases/Misc/TestContext.php b/tests/cases/Misc/TestContext.php index 902a6ba..12a9969 100644 --- a/tests/cases/Misc/TestContext.php +++ b/tests/cases/Misc/TestContext.php @@ -14,7 +14,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { public function testVerifyInitialState() { $c = new Context; foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) { - if ($m->isConstructor() || $m->isStatic()) { + if ($m->isStatic() || strpos($m->name, "__") === 0) { continue; } $method = $m->name; @@ -51,11 +51,14 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { 'annotated' => true, 'searchTerms' => ["foo", "bar"], 'annotationTerms' => ["foo", "bar"], + 'titleTerms' => ["foo", "bar"], + 'authorTerms' => ["foo", "bar"], + 'not' => (new Context)->subscription(5), ]; $times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince']; $c = new Context; foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) { - if ($m->isConstructor() || $m->isStatic()) { + if ($m->isStatic() || strpos($m->name, "__") === 0) { continue; } $method = $m->name; @@ -84,7 +87,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { } public function testCleanStringArrayValues() { - $methods = ["searchTerms", "annotationTerms"]; + $methods = ["searchTerms", "annotationTerms", "titleTerms", "authorTerms"]; $now = new \DateTime; $in = [1, 3.0, "ook", 0, true, false, null, $now, ""]; $out = ["1", "3", "ook", "0", valueInfo::normalize($now, ValueInfo::T_STRING)];