WIP on option / PJson integration

This commit is contained in:
2024-12-07 22:30:03 -05:00
parent 3bb4be3127
commit 52ec3f819c
13 changed files with 316 additions and 226 deletions

View File

@@ -2,24 +2,46 @@
namespace MyPrayerJournal\Domain;
use JsonSerializable;
use BitBadger\InspiredByFSharp\Option;
use Square\Pjson\{Json, JsonSerialize};
/**
* A record of an action taken on a request
*/
class History implements JsonSerializable
class History
{
use JsonSerialize;
/** @var string The date/time this entry was made */
#[Json]
public string $asOf = '';
/** @var RequestAction The action taken for this history entry */
#[Json]
public RequestAction $action;
/** @var string|null The text for this history entry (optional) */
#[Json('text', omit_empty: true)]
private ?string $dbText {
get => $this->text->unwrap();
set { $this->text = Option::of($value); }
}
/** @var Option<string> The text for this history entry */
public Option $text {
get => $this->text ?? Option::None();
set { $this->text = $value; }
}
/**
* @param string $asOf The date/time this entry was made
* @param RequestAction $action The action taken for this history entry
* @param string|null $text The text for this history entry (optional)
*/
public function __construct(public string $asOf, public RequestAction $action, public ?string $text = null) { }
public function jsonSerialize(): mixed
public function __construct(string $asOf, RequestAction $action, ?string $text = null)
{
$values = ['asOf' => $this->asOf, 'action' => $this->action->value];
if (isset($this->text)) $values['text'] = $this->text;
return $values;
$this->asOf = $asOf;
$this->action = $action;
$this->dbText = $text;
}
}