1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 05:44:53 +00:00
Arsse/lib/Context/ExclusionContext.php

138 lines
3.9 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\Context;
2017-08-29 14:50:31 +00:00
use JKingWeb\Arsse\Misc\ValueInfo;
class ExclusionContext {
public $folder;
public $folderShallow;
public $subscription;
public $edition;
public $article;
public $editions;
public $articles;
2017-10-13 04:04:26 +00:00
public $label;
public $labelName;
public $annotationTerms;
public $searchTerms;
public $titleTerms;
public $authorTerms;
protected $props = [];
protected function act(string $prop, int $set, $value) {
2017-08-29 14:50:31 +00:00
if ($set) {
if (is_null($value)) {
unset($this->props[$prop]);
$this->$prop = (new \ReflectionClass($this))->getDefaultProperties()[$prop];
} else {
$this->props[$prop] = true;
$this->$prop = $value;
}
return $this;
} else {
return isset($this->props[$prop]);
}
}
protected function cleanIdArray(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])) {
$spec[$a] = (int) $spec[$a];
} else {
$spec[$a] = 0;
}
}
return array_values(array_filter($spec));
}
2018-10-26 18:58:04 +00:00
protected function cleanStringArray(array $spec): array {
$spec = array_values($spec);
2019-02-22 17:34:06 +00:00
$stop = sizeof($spec);
for ($a = 0; $a < $stop; $a++) {
if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING | ValueInfo::M_DROP) ?? "")) {
$spec[$a] = $str;
} else {
unset($spec[$a]);
}
}
return array_values($spec);
}
2017-08-29 14:50:31 +00:00
public function folder(int $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2018-10-26 18:58:04 +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) {
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 edition(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 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 (isset($spec)) {
$spec = $this->cleanIdArray($spec);
2017-07-21 02:40:09 +00:00
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
2017-08-29 14:50:31 +00:00
public function articles(array $spec = null) {
if (isset($spec)) {
$spec = $this->cleanIdArray($spec);
2017-07-21 02:40:09 +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);
}
2019-02-24 01:14:52 +00:00
public function annotationTerms(array $spec = null) {
if (isset($spec)) {
$spec = $this->cleanStringArray($spec);
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function searchTerms(array $spec = null) {
if (isset($spec)) {
$spec = $this->cleanStringArray($spec);
}
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);
}
2017-08-29 14:50:31 +00:00
}