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

127 lines
3.6 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\Misc;
2017-08-29 14:50:31 +00:00
use JKingWeb\Arsse\Misc\Date;
2017-08-29 14:50:31 +00:00
class Context {
public $reverse = false;
public $limit = 0;
public $offset = 0;
public $folder;
public $subscription;
public $oldestEdition;
public $latestEdition;
public $unread = false;
public $starred = false;
public $modifiedSince;
public $notModifiedSince;
public $edition;
public $article;
public $editions;
public $articles;
protected $props = [];
protected function act(string $prop, int $set, $value) {
2017-08-29 14:50:31 +00: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 14:50:31 +00:00
for ($a = 0; $a < sizeof($spec); $a++) {
$id = $spec[$a];
2017-08-29 14:50:31 +00:00
if (is_int($id) && $id > -1) {
2017-07-21 02:40:09 +00:00
continue;
2017-08-29 14:50:31 +00:00
} elseif (is_float($id) && !fmod($id, 1) && $id >= 0) {
$spec[$a] = (int) $id;
continue;
2017-08-29 14:50:31 +00:00
} elseif (is_string($id)) {
$ch1 = strval(@intval($id));
$ch2 = strval($id);
2017-08-29 14:50:31 +00:00
if ($ch1 !== $ch2 || $id < 1) {
2017-07-21 02:40:09 +00:00
$id = 0;
}
} else {
$id = 0;
}
$spec[$a] = (int) $id;
}
return array_values(array_filter($spec));
}
2017-08-29 14:50:31 +00:00
public function reverse(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function limit(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function offset(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function folder(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function subscription(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function latestEdition(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function oldestEdition(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function unread(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function starred(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function modifiedSince($spec = null) {
$spec = Date::normalize($spec);
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function notModifiedSince($spec = null) {
$spec = Date::normalize($spec);
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function edition(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function article(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function editions(array $spec = null) {
if ($spec) {
2017-07-21 02:40:09 +00:00
$spec = $this->cleanArray($spec);
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function articles(array $spec = null) {
if ($spec) {
2017-07-21 02:40:09 +00:00
$spec = $this->cleanArray($spec);
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
}