Skip to content

Commit

Permalink
prefer Locale::canonicalize to manual upper or lowercasing
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Oct 25, 2024
1 parent b1b35a9 commit 9163aed
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions php/src/LitSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ private function setVars(array $DATA)
$this->CorpusChristi = CorpusChristi::isValid(strtoupper($value)) ? strtoupper($value) : CorpusChristi::THURSDAY;
break;
case "locale":
$value = \Locale::canonicalize($value);
$this->Locale = LitLocale::isValid($value) ? $value : LitLocale::LATIN;
if (strpos($this->Locale, '_') === false) {
$this->Locale = strtolower($this->Locale);
}
break;
case "national_calendar":
$this->NationalCalendar = $value !== "" ? strtoupper($value) : null;
Expand All @@ -95,6 +93,17 @@ private function setVars(array $DATA)
}
}

/**
* Constructor for LitSettings class.
*
* Initializes the settings for the liturgical calendar based on input data and direct access flag.
* Sets the default year to the current year. Determines the locale from cookies, HTTP headers, or defaults to Latin if unavailable.
* Ensures the Locale is canonicalized.
* Delegates further variable setting to the setVars method.
*
* @param array $DATA An array of input parameters to initialize the settings.
* @param bool $directAccess A flag indicating if the access is direct, default is false.
*/
public function __construct(array $DATA, bool $directAccess = false)
{
//set a few default values
Expand All @@ -107,15 +116,22 @@ public function __construct(array $DATA, bool $directAccess = false)
} else {
$this->Locale = LitLocale::LATIN;
}
if (strpos($this->Locale, '_') === false) {
$this->Locale = strtolower($this->Locale);
}
$this->Locale = \Locale::canonicalize($this->Locale);

$this->directAccess = $directAccess;

$this->setVars($DATA);
}

/**
* Sets the Epiphany, Ascension, CorpusChristi, and Locale settings based on the selected National Calendar.
* If the National Calendar is not set, or if it is set to "VA" (Vatican), the settings are set to their default values.
* If the National Calendar is set to a different value, the settings are set to the corresponding values from the
* NationalCalendarMetadata array.
* If the directAccess flag is set to true, the function also sets the locale for the current PHP script using the
* setlocale() function, and sets a cookie to store the current locale.
* @param string $stagingURL the URL of the staging site (used to set the domain of the cookie)
*/
private function updateSettingsByNation(string $stagingURL)
{
$NationalCalendarMetadata = null;
Expand Down Expand Up @@ -168,6 +184,13 @@ private function updateSettingsByNation(string $stagingURL)
//ini_set('date.timezone', 'Europe/Vatican');
}

/**
* Updates the internal metadata reference and then updates the settings based on the selected nation.
*
* @param array $MetaData A list of metadata about the diocesan calendars available.
* @param string $stagingURL The URL of the staging server on which the API is hosted.
* @return void
*/
public function setMetaData(array $MetaData, string $stagingURL)
{
$this->MetaData = $MetaData;
Expand Down

0 comments on commit 9163aed

Please sign in to comment.