Browse Source

Clean up coontext classes

reader
J. King 8 months ago
parent
commit
308b592b18
  1. 19
      lib/Context/AbstractContext.php
  2. 8
      lib/Context/BooleanMembers.php
  3. 15
      lib/Context/BooleanProperties.php
  4. 6
      lib/Context/Context.php
  5. 22
      lib/Context/ExclusionContext.php
  6. 29
      lib/Context/ExclusionMembers.php
  7. 36
      lib/Context/ExclusionProperties.php

19
lib/Context/AbstractContext.php

@ -10,25 +10,6 @@ abstract class AbstractContext {
protected $props = [];
protected $parent = null;
public function __construct(self $c = null) {
$this->parent = $c;
}
public function __clone() {
// if the context was cloned because its parent was cloned, change the parent to the clone
if ($this->parent) {
$t = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT, 2)[1];
if (($t['object'] ?? null) instanceof self && $t['function'] === "__clone") {
$this->parent = $t['object'];
}
}
}
/** @codeCoverageIgnore */
public function __destruct() {
unset($this->parent);
}
protected function act(string $prop, int $set, $value) {
if ($set) {
if (is_null($value)) {

8
lib/Context/BooleanMethods.php → lib/Context/BooleanMembers.php

@ -6,7 +6,13 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\Context;
trait BooleanMethods {
trait BooleanMembers {
public $unread = null;
public $starred = null;
public $hidden = null;
public $labelled = null;
public $annotated = null;
public function unread(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}

15
lib/Context/BooleanProperties.php

@ -1,15 +0,0 @@
<?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;
trait BooleanProperties {
public $unread = null;
public $starred = null;
public $hidden = null;
public $labelled = null;
public $annotated = null;
}

6
lib/Context/Context.php

@ -7,10 +7,8 @@ declare(strict_types=1);
namespace JKingWeb\Arsse\Context;
class Context extends AbstractContext {
use BooleanMethods;
use BooleanProperties;
use ExclusionMethods;
use ExclusionProperties;
use BooleanMembers;
use ExclusionMembers;
/** @var ExclusionContext */
public $not;

22
lib/Context/ExclusionContext.php

@ -7,6 +7,24 @@ declare(strict_types=1);
namespace JKingWeb\Arsse\Context;
class ExclusionContext extends AbstractContext {
use ExclusionMethods;
use ExclusionProperties;
use ExclusionMembers;
public function __construct(Context $parent = null) {
$this->parent = $parent;
}
public function __clone() {
// if the context was cloned because its parent was cloned, change the parent to the clone
if ($this->parent) {
$t = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT, 2)[1];
if (($t['object'] ?? null) instanceof Context && $t['function'] === "__clone") {
$this->parent = $t['object'];
}
}
}
/** @codeCoverageIgnore */
public function __destruct() {
unset($this->parent);
}
}

29
lib/Context/ExclusionMethods.php → lib/Context/ExclusionMembers.php

@ -9,7 +9,34 @@ namespace JKingWeb\Arsse\Context;
use JKingWeb\Arsse\Misc\ValueInfo;
use JKingWeb\Arsse\Misc\Date;
trait ExclusionMethods {
trait ExclusionMembers {
public $folder = null;
public $folders = null;
public $folderShallow = null;
public $foldersShallow = null;
public $tag = null;
public $tags = null;
public $tagName = null;
public $tagNames = null;
public $subscription = null;
public $subscriptions = null;
public $edition = null;
public $editions = null;
public $article = null;
public $articles = null;
public $label = null;
public $labels = null;
public $labelName = null;
public $labelNames = null;
public $annotationTerms = null;
public $searchTerms = null;
public $titleTerms = null;
public $authorTerms = null;
public $articleRange = [null, null];
public $editionRange = [null, null];
public $modifiedRange = [null, null];
public $markedRange = [null, null];
protected function cleanIdArray(array $spec, bool $allowZero = false): array {
$spec = array_values($spec);
for ($a = 0; $a < sizeof($spec); $a++) {

36
lib/Context/ExclusionProperties.php

@ -1,36 +0,0 @@
<?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;
trait ExclusionProperties {
public $folder = null;
public $folders = null;
public $folderShallow = null;
public $foldersShallow = null;
public $tag = null;
public $tags = null;
public $tagName = null;
public $tagNames = null;
public $subscription = null;
public $subscriptions = null;
public $edition = null;
public $editions = null;
public $article = null;
public $articles = null;
public $label = null;
public $labels = null;
public $labelName = null;
public $labelNames = null;
public $annotationTerms = null;
public $searchTerms = null;
public $titleTerms = null;
public $authorTerms = null;
public $articleRange = [null, null];
public $editionRange = [null, null];
public $modifiedRange = [null, null];
public $markedRange = [null, null];
}
Loading…
Cancel
Save