Skip to content

Commit

Permalink
fix setVars takes snake_case not PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Nov 2, 2024
1 parent 701f9b6 commit 4d57220
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions php/src/LitSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,6 @@ private function isValidDiocesanCalendar($value)
return $value !== "" && $this->Metadata !== null && in_array($value, $this->Metadata["diocesan_calendars_keys"]);
}

/**
* Converts an array's keys from snake_case to PascalCase.
*
* Given an array, this function will iterate over its keys and convert them from snake_case to PascalCase.
* If the value of a key is an array, the function will be called recursively on that array.
*
* @param array $array The array to convert.
* @return array The array with PascalCase keys.
*/
private static function snakeToPascalCaseArrayKeys(array $array): array
{
$result = [];
foreach ($array as $key => $value) {
// Convert each key from snake_case to PascalCase
$pascalCaseKey = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));

// If the value is an array, apply the function recursively
if (is_array($value)) {
$value = self::snakeToPascalCaseArrayKeys($value);
}

$result[$pascalCaseKey] = $value;
}

return $result;
}

/**
* Sets the Epiphany, Ascension, CorpusChristi, and Locale settings based on the selected National or Diocesan Calendar.
* If the National Calendar is not set, or if it is set to "VA" (Vatican), the settings are set to their default values.
Expand Down Expand Up @@ -233,8 +206,7 @@ private function updateSettingsByCalendar(): void
fn ($calendar) => $calendar["calendar_id"] === $this->DiocesanCalendar
))[0];
if (array_key_exists("settings", $DiocesanCalendarMetadata)) {
$Settings = self::snakeToPascalCaseArrayKeys($DiocesanCalendarMetadata["settings"]);
$this->setVars($Settings);
$this->setVars($DiocesanCalendarMetadata["settings"]);
}
}

Expand Down

0 comments on commit 4d57220

Please sign in to comment.