mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-10-08 02:43:50 -04:00
* 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
41 lines
944 B
PHP
41 lines
944 B
PHP
<?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;
|
|
}
|
|
}
|
|
}
|