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

Add all the other context options allowed by the TTRSS search syntax

This commit is contained in:
J. King 2019-02-25 10:46:43 -05:00
parent 2df7c25b66
commit f4a74eec5d
2 changed files with 32 additions and 3 deletions

View file

@ -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);
}
}

View file

@ -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)];