aboutsummaryrefslogtreecommitdiff
path: root/app/Models/AttributesTrait.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-12-15 23:04:29 +0100
committerGravatar GitHub <noreply@github.com> 2023-12-15 23:04:29 +0100
commit6bb45a87268157aab961a6a4a728d9a9bbe043b0 (patch)
treed1c36638d5ee61e2e663d214d724a71f07a89354 /app/Models/AttributesTrait.php
parenta3ed8269132303eebc03d3e6df822f1f101fa95b (diff)
Add filter actions (auto mark read) at category and global levels (#5942)
* Add filter actions (auto mark read) at category level fix https://github.com/FreshRSS/FreshRSS/issues/3497 * Add filter actions (auto mark read) at global level fix https://github.com/FreshRSS/FreshRSS/issues/2788 * Fix feed category ID * Minor comment
Diffstat (limited to 'app/Models/AttributesTrait.php')
-rw-r--r--app/Models/AttributesTrait.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/app/Models/AttributesTrait.php b/app/Models/AttributesTrait.php
new file mode 100644
index 000000000..39154182b
--- /dev/null
+++ b/app/Models/AttributesTrait.php
@@ -0,0 +1,40 @@
+<?php
+declare(strict_types=1);
+
+/**
+ * Logic to work with (JSON) attributes (for entries, feeds, categories, tags...).
+ */
+trait FreshRSS_AttributesTrait {
+ /**
+ * @var array<string,mixed>
+ */
+ private array $attributes = [];
+
+ /**
+ * @phpstan-return ($key is non-empty-string ? mixed : array<string,mixed>)
+ * @return array<string,mixed>|mixed|null
+ */
+ public function attributes(string $key = '') {
+ if ($key === '') {
+ return $this->attributes;
+ } else {
+ return $this->attributes[$key] ?? null;
+ }
+ }
+
+ /** @param string|array<mixed>|bool|int|null $value Value, not HTML-encoded */
+ public function _attributes(string $key, $value = null): void {
+ if ($key == '') {
+ if (is_string($value)) {
+ $value = json_decode($value, true);
+ }
+ if (is_array($value)) {
+ $this->attributes = $value;
+ }
+ } elseif ($value === null) {
+ unset($this->attributes[$key]);
+ } else {
+ $this->attributes[$key] = $value;
+ }
+ }
+}