mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 08:34:56 +00:00
e74a3ae3cb
- Specifying a non-integer parent no longer silently casts to 0 or 1 - Specifying a folder ID of 0 now always converts to null automatically - Performing both a rename and move to root in the same operation no longer results in potential duplicates - Calling folderSetProperties with an empty data array no peforms an update; it now returns false before the update call - Modification timestamps are now actually updated when a folder is modified - Constraint violation exceptions triggered by code (rather than the database) now print a message - Renaming a folder or subscription to a non-string value (e.g. an array) throws an exception rather than silently casting - Added tests to better cover all the above - Centralized the normalization of integers and title strings into a new ValueInfo static class
116 lines
3.2 KiB
PHP
116 lines
3.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace JKingWeb\Arsse\Misc;
|
|
|
|
use JKingWeb\Arsse\Misc\Date;
|
|
use JKingWeb\Arsse\Misc\ValueInfo;
|
|
|
|
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) {
|
|
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);
|
|
for ($a = 0; $a < sizeof($spec); $a++) {
|
|
if(ValueInfo::int($spec[$a])===ValueInfo::VALID) {
|
|
$spec[$a] = (int) $spec[$a];
|
|
} else {
|
|
$spec[$a] = 0;
|
|
}
|
|
}
|
|
return array_values(array_filter($spec));
|
|
}
|
|
|
|
public function reverse(bool $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function limit(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function offset(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function folder(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function subscription(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function latestEdition(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function oldestEdition(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function unread(bool $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function starred(bool $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function modifiedSince($spec = null) {
|
|
$spec = Date::normalize($spec);
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function notModifiedSince($spec = null) {
|
|
$spec = Date::normalize($spec);
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function edition(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function article(int $spec = null) {
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function editions(array $spec = null) {
|
|
if ($spec) {
|
|
$spec = $this->cleanArray($spec);
|
|
}
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
|
|
public function articles(array $spec = null) {
|
|
if ($spec) {
|
|
$spec = $this->cleanArray($spec);
|
|
}
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
}
|
|
}
|