WIP on vanilla PHP framework

This commit is contained in:
2024-06-20 23:06:31 -04:00
parent 24c503385e
commit 41853a7645
16 changed files with 562 additions and 6 deletions

16
src/lib/History.php Normal file
View File

@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
namespace MyPrayerJournal;
/**
* A record of an action taken on a request
*/
class History
{
/**
* @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) { }
}

15
src/lib/Note.php Normal file
View File

@@ -0,0 +1,15 @@
<?php declare(strict_types=1);
namespace MyPrayerJournal;
/**
* A note entered on a prayer request
*/
class Note
{
/**
* @param string $asOf The date/time this note was recorded
* @param string $text The text of the note
*/
public function __construct(public string $asOf, public string $text) { }
}

15
src/lib/Recurrence.php Normal file
View File

@@ -0,0 +1,15 @@
<?php declare(strict_types=1);
namespace MyPrayerJournal;
/**
* The recurrence for a prayer request
*/
class Recurrence
{
/**
* @param RecurrencePeriod $period The recurrence period
* @param int|null $interval How many of the periods will pass before the request is visible again
*/
public function __construct(public RecurrencePeriod $period, public ?int $interval = null) { }
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
namespace MyPrayerJournal;
/**
* The type of recurrence a request can have
*/
enum RecurrencePeriod
{
/** Requests, once prayed, are available again immediately */
case Immediate;
/** Requests, once prayed, appear again in a number of hours */
case Hours;
/** Requests, once prayed, appear again in a number of days */
case Days;
/** Requests, once prayed, appear again in a number of weeks */
case Weeks;
}

33
src/lib/Request.php Normal file
View File

@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
namespace MyPrayerJournal;
use Exception;
use Visus\Cuid2\Cuid2;
/**
* A prayer request
*/
class Request
{
/**
* @param string $id The ID for the request
* @param string $enteredOn The date/time this request was originally entered
* @param string $userId The ID of the user to whom this request belongs
* @param string|null $snoozedUntil The date/time the snooze expires for this request (null = not snoozed)
* @param string|null $showAfter The date/time the current recurrence period is over (null = immediate)
* @param Recurrence $recurrence The recurrence for this request
* @param array|History[] $history The history of this request
* @param array|Note[] $notes Notes regarding this request
* @throws Exception If the ID generation fails
*/
public function __construct(public string $id = '', public string $enteredOn = '', public string $userId = '',
public ?string $snoozedUntil = null, public ?string $showAfter = null,
public Recurrence $recurrence = new Recurrence(RecurrencePeriod::Immediate),
public array $history = [], public array $notes = [])
{
if ($id == '') {
$this->id = (new Cuid2())->toString();
}
}
}

21
src/lib/RequestAction.php Normal file
View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
namespace MyPrayerJournal;
/**
* An action taken on a prayer request
*/
enum RequestAction
{
/** The request was created */
case Created;
/** The request was marked as having been prayed for */
case Prayed;
/** The request was updated */
case Updated;
/** The request was marked as answered */
case Answered;
}