Arsse/lib/Misc/Context.php

168 lines
4.7 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\Misc;
2017-08-29 10:50:31 -04:00
use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Misc\ValueInfo;
2017-08-29 10:50:31 -04:00
class Context {
public $reverse = false;
public $limit = 0;
public $offset = 0;
public $folder;
public $folderShallow;
public $subscription;
public $oldestArticle;
public $latestArticle;
public $oldestEdition;
public $latestEdition;
public $unread = null;
public $starred = null;
public $modifiedSince;
public $notModifiedSince;
public $markedSince;
public $notMarkedSince;
public $edition;
public $article;
public $editions;
public $articles;
2017-10-13 00:04:26 -04:00
public $label;
public $labelName;
public $labelled = null;
public $annotated = null;
protected $props = [];
protected function act(string $prop, int $set, $value) {
2017-08-29 10:50:31 -04:00
if ($set) {
$this->props[$prop] = true;
$this->$prop = $value;
return $this;
} else {
return isset($this->props[$prop]);
}
}
protected function cleanArray(array $spec): array {
$spec = array_values($spec);
2017-08-29 10:50:31 -04:00
for ($a = 0; $a < sizeof($spec); $a++) {
2017-09-28 10:16:24 -04:00
if (ValueInfo::id($spec[$a])) {
$spec[$a] = (int) $spec[$a];
} else {
$spec[$a] = 0;
}
}
return array_values(array_filter($spec));
}
2017-08-29 10:50:31 -04:00
public function reverse(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function limit(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function offset(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function folder(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function folderShallow(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function subscription(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function latestArticle(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function oldestArticle(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function latestEdition(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function oldestEdition(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function unread(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function starred(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function modifiedSince($spec = null) {
$spec = Date::normalize($spec);
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function notModifiedSince($spec = null) {
$spec = Date::normalize($spec);
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function markedSince($spec = null) {
$spec = Date::normalize($spec);
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function notMarkedSince($spec = null) {
$spec = Date::normalize($spec);
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function edition(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function article(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function editions(array $spec = null) {
if ($spec) {
2017-07-20 22:40:09 -04:00
$spec = $this->cleanArray($spec);
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
public function articles(array $spec = null) {
if ($spec) {
2017-07-20 22:40:09 -04:00
$spec = $this->cleanArray($spec);
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-10-13 00:04:26 -04: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);
}
public function labelled(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function annotated(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 10:50:31 -04:00
}