2017-06-18 14:23:37 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-06-18 14:23:37 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Misc;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-07-17 11:47:57 +00:00
|
|
|
use JKingWeb\Arsse\Misc\Date;
|
2017-09-26 20:45:41 +00:00
|
|
|
use JKingWeb\Arsse\Misc\ValueInfo;
|
2017-06-18 14:23:37 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
class Context {
|
2017-06-18 14:23:37 +00:00
|
|
|
public $reverse = false;
|
|
|
|
public $limit = 0;
|
|
|
|
public $offset = 0;
|
|
|
|
public $folder;
|
2017-11-16 20:56:14 +00:00
|
|
|
public $folderShallow;
|
2017-06-18 14:23:37 +00:00
|
|
|
public $subscription;
|
2017-11-18 21:06:49 +00:00
|
|
|
public $oldestArticle;
|
|
|
|
public $latestArticle;
|
2017-06-18 14:23:37 +00:00
|
|
|
public $oldestEdition;
|
|
|
|
public $latestEdition;
|
2017-11-09 19:21:12 +00:00
|
|
|
public $unread = null;
|
|
|
|
public $starred = null;
|
2017-06-18 14:23:37 +00:00
|
|
|
public $modifiedSince;
|
|
|
|
public $notModifiedSince;
|
2017-11-17 22:52:00 +00:00
|
|
|
public $markedSince;
|
|
|
|
public $notMarkedSince;
|
2017-06-18 14:23:37 +00:00
|
|
|
public $edition;
|
|
|
|
public $article;
|
2017-07-07 02:53:17 +00:00
|
|
|
public $editions;
|
|
|
|
public $articles;
|
2017-10-13 04:04:26 +00:00
|
|
|
public $label;
|
|
|
|
public $labelName;
|
2017-11-16 20:56:14 +00:00
|
|
|
public $labelled = null;
|
2017-11-18 00:08:35 +00:00
|
|
|
public $annotated = null;
|
2017-06-18 14:23:37 +00:00
|
|
|
|
|
|
|
protected $props = [];
|
|
|
|
|
|
|
|
protected function act(string $prop, int $set, $value) {
|
2017-08-29 14:50:31 +00:00
|
|
|
if ($set) {
|
2018-12-05 01:41:21 +00:00
|
|
|
if (is_null($value)) {
|
|
|
|
unset($this->props[$prop]);
|
|
|
|
$this->$prop = (new \ReflectionClass($this))->getDefaultProperties()[$prop];
|
|
|
|
} else {
|
|
|
|
$this->props[$prop] = true;
|
|
|
|
$this->$prop = $value;
|
|
|
|
}
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this;
|
|
|
|
} else {
|
|
|
|
return isset($this->props[$prop]);
|
|
|
|
}
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
|
|
|
|
protected function cleanArray(array $spec): array {
|
|
|
|
$spec = array_values($spec);
|
2017-08-29 14:50:31 +00:00
|
|
|
for ($a = 0; $a < sizeof($spec); $a++) {
|
2017-09-28 14:16:24 +00:00
|
|
|
if (ValueInfo::id($spec[$a])) {
|
2017-09-26 20:45:41 +00:00
|
|
|
$spec[$a] = (int) $spec[$a];
|
2017-07-07 02:53:17 +00:00
|
|
|
} else {
|
2017-09-26 20:45:41 +00:00
|
|
|
$spec[$a] = 0;
|
2017-07-07 02:53:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return array_values(array_filter($spec));
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function reverse(bool $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function limit(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function offset(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function folder(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-11-16 20:56:14 +00:00
|
|
|
public function folderShallow(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function subscription(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-11-18 21:06:49 +00:00
|
|
|
public function latestArticle(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-11-18 21:06:49 +00:00
|
|
|
public function oldestArticle(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function latestEdition(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function oldestEdition(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function unread(bool $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function starred(bool $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function modifiedSince($spec = null) {
|
2017-07-17 11:47:57 +00:00
|
|
|
$spec = Date::normalize($spec);
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function notModifiedSince($spec = null) {
|
2017-07-17 11:47:57 +00:00
|
|
|
$spec = Date::normalize($spec);
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
2017-11-17 22:52:00 +00:00
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-11-17 22:52:00 +00:00
|
|
|
public function markedSince($spec = null) {
|
|
|
|
$spec = Date::normalize($spec);
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-11-17 22:52:00 +00:00
|
|
|
public function notMarkedSince($spec = null) {
|
|
|
|
$spec = Date::normalize($spec);
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
2017-06-18 14:23:37 +00:00
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function edition(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function article(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function editions(array $spec = null) {
|
2018-12-05 01:41:21 +00:00
|
|
|
if (isset($spec)) {
|
2017-07-21 02:40:09 +00:00
|
|
|
$spec = $this->cleanArray($spec);
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function articles(array $spec = null) {
|
2018-12-05 01:41:21 +00:00
|
|
|
if (isset($spec)) {
|
2017-07-21 02:40:09 +00:00
|
|
|
$spec = $this->cleanArray($spec);
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-10-13 04:04:26 +00:00
|
|
|
|
|
|
|
public function label(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function labelName(string $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-11-16 20:56:14 +00:00
|
|
|
|
|
|
|
public function labelled(bool $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-11-18 00:08:35 +00:00
|
|
|
|
|
|
|
public function annotated(bool $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|