HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Globalization/AbstractCultureParser.php
<?php

namespace App\Komma\Globalization;

/**
 * Class AbstractCultureParser
 *
 * Can parse a culture name
 * Based of the C# variant
 */
abstract class AbstractCultureParser
{
    /** @var string ISO 15924 script */
    protected $scriptTagCountry = '';

    /** @var string two letter language code or a three-letter code derived from ISO 639-2 if not available */
    protected $languageCode2 = '';

    /** @var string two letter country/regioncode2 */
    protected $countryOrRegionCode2 = '';

    /** @var int a language code id which holds current culture info data */
    protected $cultureId = -1;

    /** @var string */
    protected $currentName = '';

    /**
     * The format for the culture name based on RFC 4646 is languagecode2>-country/regioncode2, where languagecode2 is the two-letter
     * language code and country/regioncode2 is the two-letter subculture code. Examples include ja-JP for Japanese (Japan)
     * and en-US for English (United States). In cases where a two-letter language code is not available,
     * a three-letter code derived from ISO 639-2 is used.
     *
     * Notice that some culture names also specify an ISO 15924 script. For example, Cyrl specifies the Cyrillic script
     * and Latn specifies the Latin script. A culture name that includes a script uses the pattern languagecode2-scripttag-country/regioncode2.
     * An example of this type of culture name is uz-Cyrl-UZ for Uzbek (Cyrillic, Uzbekistan).
     *
     * A neutral culture is specified by only the two-letter lowercase language code. For example, fr specifies the neutral culture for French, and de specifies the neutral culture for German.
     *
     * CultureInfo constructor.
     * @param string $name
     */
    public function __construct(string $name)
    {
        $this->parseName($name);
        $this->setId();
        $this->currentName = implode('-', array_values(array_filter([strtolower($this->languageCode2), ucfirst(strtolower($this->scriptTagCountry)), strtoupper($this->countryOrRegionCode2)])));
    }

    /**
     * Parses a name and extracts culture and region info from it
     *
     * @param string $name
     */
    abstract protected function parseName(string $name);

    /**
     * Looks up any combination of languageCode2, scriptTagCountry and countryOrRegionCode2 in the data in
     * AbstractCultureData and stores the ID
     */
    abstract protected function setId();

    /**
     * @return int
     */
    public function getCultureId(): int
    {
        return $this->cultureId;
    }
}