Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.1.0 #173

Merged
merged 23 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aad1872
Bumping version to 2.1.0
bfren Sep 3, 2024
c3084ce
Adding support for URI prefixes - #163
bfren Sep 3, 2024
bfbb765
Adding prefix to API endpoints - #163
bfren Sep 3, 2024
412731d
Adding shared last modified header function - #172
bfren Sep 3, 2024
8873e42
Adding plain text response type - #172
bfren Sep 3, 2024
f071e22
Making JSON response consistent with new Plain Text response - #172
bfren Sep 3, 2024
f59bb8e
Adding robots.txt endpoint class - #172
bfren Sep 3, 2024
5712427
Ensuring strict compliance - #172
bfren Sep 3, 2024
f469ffd
Adding PHPStan check to dev workflow - #171
bfren Sep 3, 2024
c677e17
Updating PHPStan - #171
bfren Sep 3, 2024
111c693
Moving PHPStan check to test job - #171
bfren Sep 3, 2024
00893f0
Updating PHPStan - #175
bfren Sep 20, 2024
d78b907
Supporting 'Guest Speaker' - #176
bfren Sep 20, 2024
201a4a9
Adding API to preload route - #163
bfren Sep 20, 2024
d46bee8
Updating endpoint links and comments - #163
bfren Sep 20, 2024
f0e6772
Fixing endpoint matching against URI - #163
bfren Sep 20, 2024
a96fbd9
Moving Guest Speaker replacement - #176
bfren Sep 20, 2024
46c9866
Removing Guest Speaker property from Combined_Service - #176
bfren Sep 20, 2024
83161a8
Load Guest Speaker field from Baserow - #176
bfren Sep 20, 2024
cc84883
Fixing readings spacing - #177
bfren Sep 20, 2024
8505b20
Correctly handling plural / singular psalms - #174
bfren Sep 20, 2024
b68bf11
Adding PHPDoc to Psalms::pluralise - #174
bfren Sep 20, 2024
a04251b
Updating Dockerfile to 7.2.21 - #178
bfren Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ jobs:
-
name: Checkout code
uses: actions/checkout@v4
-
name: Run PHPStan checks
run: |
./check.sh
build:
runs-on: ubuntu-latest
needs: test
steps:
-
name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.4
2.1.0
2 changes: 1 addition & 1 deletion VERSION_MINOR
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0
2.1
2 changes: 1 addition & 1 deletion check.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

LEVEL=7
echo "Using PHPStan to check source with level ${LEVEL}."
vendor/bin/phpstan analyse --level=${LEVEL} src
php vendor/bin/phpstan analyse --level=${LEVEL} src
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require-dev": {
"require": {
"phpstan/phpstan": "^1.12"
}
}
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bfren/nginx-php:php8.3-7.2.20
FROM bfren/nginx-php:php8.3-7.2.21

LABEL org.opencontainers.image.source="https://github.com/bfren/obadiah"

Expand Down
2 changes: 1 addition & 1 deletion src/api/ajax/ajax.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function get_input(): mixed
}

/**
* POST: /ajax/month (called from Prayer Calendar edit page).
* POST: /api/ajax/month (called from Prayer Calendar edit page).
*
* @return Json JSON result.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/api/preload/preload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Preload extends Endpoint
{
/**
* GET: /preload
* GET: /api/preload
*
* @return Json
*/
Expand Down
18 changes: 18 additions & 0 deletions src/classes/helpers/arr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ public static function get_boolean(array $array, int|string $key, bool $default
return $default;
}

/**
* Safely get the last value from an array.
*
* @template T
* @param T[]|array<int|string, T> $array Array of values.
* @param T|null $default Default value to return if array is empty.
* @return T Last value, or $default if array is empty.
*/
public static function get_last(array $array, mixed $default = null): mixed
{
$key = array_key_last($array);
if ($key === null) {
return $default;
}

return self::get($array, $key);
}

/**
* Safely get an integer value from an array.
*
Expand Down
30 changes: 30 additions & 0 deletions src/classes/helpers/psalms.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Obadiah\Helpers;

use Obadiah\App;

App::check();

class Psalms
{
/**
* Return singular or plural Psalm' or 'Psalms' based on $psalms.
*
* @param string[]|string $psalms The psalms to check.
* @return string Either 'Psalm' or 'Psalms'.
*/
public static function pluralise(array|string $psalms): string
{
// split string by comma
if (is_string($psalms)) {
$psalms = Arr::map(explode(",", $psalms), "trim");
}

// return Psalm or Psalms based on the array count
return match (count($psalms)) {
1 => "Psalm",
default => "Psalms"
};
}
}
6 changes: 4 additions & 2 deletions src/classes/lectionary/lectionary.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function __construct()
"Title",
"Main Reading",
"Additional Reading",
"Psalms"
"Psalms",
"Guest Speaker"
);
$service_results = $service_table->get(array("include" => join(",", $service)));

Expand Down Expand Up @@ -95,7 +96,8 @@ public function __construct()
title: Arr::get($service, "Title"),
main_reading: Arr::get($service, "Main Reading"),
additional_reading: Arr::get($service, "Additional Reading"),
psalms: Arr::map(explode(";", Arr::get($service, "Psalms", "")), "trim")
psalms: Arr::map(explode(";", Arr::get($service, "Psalms", "")), "trim"),
guest_speaker: Arr::get($service, "Guest Speaker")
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/classes/lectionary/service.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Service
* @param string|null $main_reading Optional main reading.
* @param string|null $additional_reading Optional additional reading.
* @param string[] $psalms Optional psalms.
* @param string|null $guest_speaker Optional guest speaker.
* @return void
*/
public function __construct(
Expand All @@ -32,6 +33,7 @@ public function __construct(
public readonly ?string $title,
public readonly ?string $main_reading,
public readonly ?string $additional_reading,
public readonly array $psalms
public readonly array $psalms,
public readonly ?string $guest_speaker
) {}
}
3 changes: 2 additions & 1 deletion src/classes/refresh/day.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Obadiah\Cache\Cache;
use Obadiah\Config\Config as C;
use Obadiah\Helpers\Arr;
use Obadiah\Helpers\Psalms;
use Obadiah\Prayer\Person;

App::check();
Expand Down Expand Up @@ -51,7 +52,7 @@ public function get_description(string $separator = "\\n"): string
// add readings
if ($this->readings) {
$description[] = "= Readings =";
$description[] = sprintf("1: Psalms %s", $this->readings->ot_psalms);
$description[] = sprintf("1: %s %s", Psalms::pluralise($this->readings->ot_psalms), $this->readings->ot_psalms);
$description[] = sprintf("2: %s", $this->readings->ot_1);
$description[] = sprintf("3: %s", $this->readings->ot_2);
$description[] = sprintf("4: %s", $this->readings->nt_gospels);
Expand Down
20 changes: 15 additions & 5 deletions src/classes/response/action.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Obadiah\Response;

use Obadiah\App;
use Obadiah\Pages\Error\Error;
use Obadiah\Request\Request;
use Throwable;

Expand All @@ -21,7 +20,7 @@ abstract class Action
/**
* Add default headers.
*
* @param int $status HTTP status code.
* @param int $status HTTP status code.
* @return void
*/
protected function __construct(
Expand All @@ -33,8 +32,8 @@ protected function __construct(
/**
* Add a header to the response.
*
* @param string $key Header key.
* @param string $value Header value.
* @param string $key Header key.
* @param string $value Header value.
* @return void
*/
protected function add_header(string $key, string $value)
Expand All @@ -45,7 +44,7 @@ protected function add_header(string $key, string $value)
/**
* Add debug headers if $debug is set in Request.
*
* @return bool True if the debug headers have been added.
* @return bool True if the debug headers have been added.
*/
protected function add_debug_headers(): bool
{
Expand All @@ -57,6 +56,17 @@ protected function add_debug_headers(): bool
return false;
}

/**
* Add Last-Modified header.
*
* @param int|null $last_modified Optional Last Modified value - if null will use current time.
* @return void
*/
protected function add_last_modified_header(?int $last_modified = null)
{
$this->add_header("Last-Modified", gmdate("D, d M Y H:i:s", $last_modified ?: time()));
}

/**
* Send HTTP status and configured headers to the response.
*
Expand Down
4 changes: 2 additions & 2 deletions src/classes/response/json.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Json extends Action
{
/**
* Create Json and add headers.
* Store JSON model and add headers.
*
* @param mixed $model JSON model.
* @param int $status HTTP status code.
Expand All @@ -33,7 +33,7 @@ public function __construct(
// add standard JSON headers
$this->add_header("Access-Control-Allow-Origin", "*");
$this->add_header("Content-Type", "text/json; charset=utf-8");
$this->add_header("Last-Modified", gmdate("D, d M Y H:i:s", $last_modified ?: time()));
$this->add_last_modified_header($last_modified);
}

/**
Expand Down
46 changes: 46 additions & 0 deletions src/classes/response/text.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Obadiah\Response;

use Obadiah\App;

App::check();

class Text extends Action
{
/**
* Store plain text and add headers.
*
* @param string $text Plain text value.
* @param int $status HTTP status code.
* @param int|null $last_modified Optional last modified timestamp.
* @return void
*/
public function __construct(
public readonly string $text,
int $status = 200,
?int $last_modified = null
) {
// add default headers
parent::__construct($status);

// add debug headers
if ($this->add_debug_headers()) {
return;
}

// add standard plain text headers
$this->add_header("Content-Type", "text/plain; charset=utf-8");
$this->add_last_modified_header($last_modified);
}

/**
* Execute the action, encoding and printing the plain text value.
*
* @return void
*/
public function execute(): void
{
print_r($this->text);
}
}
13 changes: 12 additions & 1 deletion src/classes/rota/builder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public static function build_combined_rota(Lectionary $lectionary, array $servic
continue;
}

// replace any instances of 'Guest Speaker'
$ministries = [];
foreach ($rota_service->ministries as $name => $ministry) {
$ministries[$name] = new Service_Ministry(
abbreviation: $ministry->abbreviation,
people: Arr::map($ministry->people, function ($person) use ($lectionary_service) {
return $person === "Guest Speaker" ? $lectionary_service->guest_speaker : $person;
})
);
};

// create Combined Service object
$c_services[] = new Combined_Service(
start: $rota_service->start,
Expand All @@ -85,7 +96,7 @@ public static function build_combined_rota(Lectionary $lectionary, array $servic
main_reading: $lectionary_service->main_reading,
additional_reading: $lectionary_service->additional_reading,
psalms: $lectionary_service->psalms ?: [],
ministries: $rota_service->ministries
ministries: $ministries
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/classes/rota/combined-service.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Combined_Service
* @param string|null $main_reading Optional main reading.
* @param string|null $additional_reading Optional additional reading.
* @param string[] $psalms Optional psalms.
* @param Service_Ministry[] $ministries Ministries from the rota.
* @param array<string, Service_Ministry> $ministries Ministries from the rota.
* @return void
*/
public function __construct(
Expand Down
Loading