Skip to content

Commit 571e276

Browse files
committed
add an include_empty parameter to request all Roman Missals
from the /missals endpoint, even if they have no defined data
1 parent 4e981f5 commit 571e276

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/Params/MissalsParams.php

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class MissalsParams
1010
{
11+
public bool $IncludeEmpty = false;
1112
public ?string $Region = null;
1213
public ?int $Year = null;
1314
public ?string $Locale = null;
@@ -74,6 +75,12 @@ public function setData(array $DATA = [])
7475
Missals::produceErrorResponse(StatusCode::BAD_REQUEST, $message);
7576
}
7677
break;
78+
case 'include_empty':
79+
$this->IncludeEmpty = filter_var($value, FILTER_VALIDATE_BOOLEAN);
80+
break;
81+
default:
82+
// do nothing
83+
break;
7784
}
7885
}
7986
}

src/Paths/Missals.php

+25-5
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ private static function initPayloadFromRequestBody(): ?object
8080
* If it does not find a valid locale, it will default to 'la' (Latin).
8181
*
8282
* If the object does not have a 'region' property, it will not set the
83-
* 'REGION' key in the returned array.
83+
* 'region' key in the returned array.
8484
*
8585
* If the object does not have a 'year' property, it will not set the
86-
* 'YEAR' key in the returned array.
86+
* 'year' key in the returned array.
8787
*
8888
* @param ?object $payload the JSON or YAML encoded object or null if the
8989
* request body was not a JSON or YAML encoded object
9090
* @return array the initialized request parameters
9191
*/
92-
private static function initPayload(?object $payload): array
92+
private static function initGetPostParams(?object $payload): array
9393
{
9494
$data = [];
9595
if ($payload !== null && property_exists($payload, 'locale')) {
@@ -108,6 +108,9 @@ private static function initPayload(?object $payload): array
108108
if (property_exists($payload, 'year')) {
109109
$data["year"] = $payload->year;
110110
}
111+
if (property_exists($payload, 'include_empty')) {
112+
$data["include_empty"] = $payload->include_empty;
113+
}
111114
return $data;
112115
}
113116

@@ -132,12 +135,12 @@ private static function initRequestParams(): array
132135
if (in_array(self::$Core->getRequestMethod(), [RequestMethod::POST, RequestMethod::PUT, RequestMethod::PATCH])) {
133136
$payload = self::initPayloadFromRequestBody();
134137
if (self::$Core->getRequestMethod() === RequestMethod::POST) {
135-
$data = self::initPayload($payload);
138+
$data = self::initGetPostParams($payload);
136139
} else {
137140
$data["PAYLOAD"] = $payload;
138141
}
139142
} elseif (self::$Core->getRequestMethod() === RequestMethod::GET) {
140-
$data = self::initPayload((object)$_GET);
143+
$data = self::initGetPostParams((object)$_GET);
141144
}
142145
return $data;
143146
}
@@ -418,5 +421,22 @@ public static function init(array $requestPathParts = [])
418421
}
419422
// we only set the request parameters after we have collected the MissalRegions and MissalYears
420423
self::$params->setData(self::initRequestParams());
424+
425+
// If an explicit request is made to include all Missals defined in the RomanMissal enum,
426+
// even if there is no data for them in the jsondata/sourcedata/missals directory,
427+
// we add them to the response.
428+
if (self::$params->IncludeEmpty) {
429+
$allMissals = RomanMissal::produceMetadata(true);
430+
foreach ($allMissals as $missal) {
431+
if (null === array_find(self::$missalsIndex->litcal_missals, function ($m) use ($missal) {
432+
return $m->missal_id === $missal->missal_id;
433+
})) {
434+
//$missal->api_path = false;
435+
self::$missalsIndex->litcal_missals[] = $missal;
436+
self::$params->addMissalRegion($missal->region);
437+
self::$params->addMissalYear($missal->year_published);
438+
}
439+
}
440+
}
421441
}
422442
}

0 commit comments

Comments
 (0)