Load currency definitions

@return \SimpleXMLElement
971864
protected static function getDefinitions()
    {
        if (empty(self::$definitions)) {
            self::$definitions = \simplexml_load_file(__DIR__ . '/currencies.xml');
        }

        return self::$definitions;
    }
1211824
public function getCurrencySymbol($currencyCode = null): string
    {
        if (!extension_loaded('intl')) {
            throw new InvalidConfigException('Locale component requires PHP intl extension to be installed.');
        }

        $locale = $this->locale;

        if ($currencyCode !== null) {
            $locale = $locale->withCurrency($currencyCode);
        }

        $formatter = new NumberFormatter((string)$locale, NumberFormatter::CURRENCY);
        return $formatter->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
    }
275666
public static function parseByIntl(
        $money,
        $forceCurrency = null,
        $locale = null,
        Currencies $currencies = null,
        $style = NumberFormatter::CURRENCY
    ) {
        $numberFormatter = new NumberFormatter($locale ?: static::getLocale(), $style);
        $parser = new IntlMoneyParser($numberFormatter, $currencies ?: static::getCurrencies());

        return self::parseByParser($parser, $money, $forceCurrency);
    }
797199
private function addCurrencySymbol(string $value, ?string $currency = null): string
    {
        $currency = $currency ?? $this->defaultCurrency;
        $locale = \Locale::getDefault();

        if (!isset(self::$patterns[$locale])) {
            self::$patterns[$locale] = [];
        }

        if (!isset(self::$patterns[$locale][$currency])) {
            $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
            $pattern = $formatter->formatCurrency(123.00, $currency);

            // 1=left-position currency, 2=left-space, 3=right-space, 4=left-position currency.
            // With non latin number scripts.
            preg_match(
                '/^([^\s\xc2\xa0]*)([\s\xc2\xa0]*)\p{N}{3}(?:[,.]\p{N}+)?([\s\xc2\xa0]*)([^\s\xc2\xa0]*)$/iu',
                $pattern,
                $matches
            );

            if (!empty($matches[1])) {
                self::$patterns[$locale][$currency] = ['%1$s'.$matches[2].'%2$s', $matches[1]];
            } elseif (!empty($matches[4])) {
                self::$patterns[$locale][$currency] = ['%2$s'.$matches[3].'%1$s', $matches[4]];
            } else {
                throw new \InvalidArgumentException(
                    sprintf('Locale "%s" with currency "%s" does not provide a currency position.', $locale, $currency)
                );
            }
        }

        return sprintf(self::$patterns[$locale][$currency][0], self::$patterns[$locale][$currency][1], $value);
    }
207243
protected function LoadElement()
    {
        if ($this->Content()->Exists()) {
            return $this->ElementSchema()->ByContent($this->Content());
        }
        return $this->ElementSchema()->CreateInstance();
    }
1329257
public static function getCurrencyBundle()
    {
        @trigger_error(sprintf('The method "%s()" is deprecated since Symfony 4.3, use "%s" instead.', __METHOD__, Currencies::class), E_USER_DEPRECATED);

        if (null === self::$currencyBundle) {
            self::$currencyBundle = new CurrencyBundle(
                self::getDataDirectory().'/'.self::CURRENCY_DIR,
                self::getEntryReader(),
                self::$localeBundle ?? self::$localeBundle = new LocaleBundle(self::getDataDirectory().'/'.self::LOCALE_DIR, self::getEntryReader())
            );
        }

        return self::$currencyBundle;
    }
153526
protected function getXML()
    {
        // if our cached data is ok
        if ($this->fetchedTimestamp !== null && (time() < $this->fetchedTimestamp + self::FETCH_CACHE_TIME) && $this->fetchedData !== null) {
            return $this->fetchedData;
        }

        //get current exchange rate XML
        $curlHandle = curl_init();
        curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curlHandle, CURLOPT_URL, "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
        $curlResponse = curl_exec($curlHandle);
        curl_close($curlHandle);

        // FIXME! Better error handling

        $this->fetchedData = $curlResponse;
        $this->fetchedTimestamp = time();

        return $this->fetchedData;
    }
668066
public function getXML(\DOMDocument $document)
    {
        $xml = $document->createElement('ns1:Payment');

        if (!empty($this->hostedDataId)) {
            $hostedDataId = $document->createElement('ns1:HostedDataID');
            $hostedDataId->textContent = $this->hostedDataId;

            $xml->appendChild($hostedDataId);
        }

        if (!empty($this->amount)) {
            $amount                = $document->createElement('ns1:ChargeTotal');
            $amount->textContent   = $this->amount;
            $currency              = $document->createElement('ns1:Currency');
            $currency->textContent = self::CURRENCY_EUR;

            $xml->appendChild($amount);
            $xml->appendChild($currency);
        }

        return $xml;
    }
928590
public function getCurrency()
    {
        // @todo
        $result = array (
            Meta::Currency => $this->source->currency_code,
            Meta::CurrencyRate => (float) $this->source->conversion_rate,
            Meta::CurrencyDoConvert => true,
        );
        return $result;
    }
834947
public function getCurrency() : ?string 
    {
        if ( ! $this->hasCurrency()) {
            $this->setCurrency($this->getDefaultCurrency());
        }
        return $this->currency;
    }
511726
private function loadCurrencyFromSession()
    {
        $currencyIdInSession = $this
            ->currencySessionManager
            ->get();

        return $currencyIdInSession
            ? $this->currency = $this
                ->currencyRepository
                ->find($currencyIdInSession)
            : null;
    }
296334
protected function buildCurrencyField()
    {
        $name = $this->getName();

        // Validate allowed currencies
        $currencyValue = $this->fieldCurrency ? $this->fieldCurrency->dataValue() : null;
        $allowedCurrencies = $this->getAllowedCurrencies();
        if (count($allowedCurrencies) === 1) {
            // Hidden field for single currency
            $field = HiddenField::create("{$name}[Currency]");
            reset($allowedCurrencies);
            $currencyValue = key($allowedCurrencies);
        } elseif ($allowedCurrencies) {
            // Dropdown field for multiple currencies
            $field = DropdownField::create(
                "{$name}[Currency]",
                _t('SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY', 'Currency'),
                $allowedCurrencies
            );
        } else {
            // Free-text entry for currency value
            $field = TextField::create(
                "{$name}[Currency]",
                _t('SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY', 'Currency')
            );
        }

        $field->setReadonly($this->isReadonly());
        $field->setDisabled($this->isDisabled());
        if ($currencyValue) {
            $field->setValue($currencyValue);
        }
        $this->fieldCurrency = $field;
        return $field;
    }
1052628
public static function getCurrencyList()
    {
        return [
            'EUR' => ['name' => 'Euro',                  'code' => 978, 'fraction' => 2],
            'USD' => ['name' => 'Dollar Américain',      'code' => 840, 'fraction' => 2],
            'CHF' => ['name' => 'Franc Suisse',          'code' => 756, 'fraction' => 2],
            'GBP' => ['name' => 'Livre Sterling',        'code' => 826, 'fraction' => 2],
            'CAD' => ['name' => 'Dollar Canadien',       'code' => 124, 'fraction' => 2],
            'JPY' => ['name' => 'Yen',                   'code' => 392, 'fraction' => 0],
            'MXN' => ['name' => 'Peso Mexicain',         'code' => 484, 'fraction' => 2],
            'TRY' => ['name' => 'Nouvelle Livre Turque', 'code' => 949, 'fraction' => 2],
            'AUD' => ['name' => 'Dollar Australien',     'code' => 036, 'fraction' => 2],
            'NZD' => ['name' => 'Dollar Néo-Zélandais',  'code' => 554, 'fraction' => 2],
            'NOK' => ['name' => 'Couronne Norvégienne',  'code' => 578, 'fraction' => 2],
            'BRL' => ['name' => 'Real Brésilien',        'code' => 986, 'fraction' => 2],
            'ARS' => ['name' => 'Peso Argentin',         'code' => 032, 'fraction' => 2],
            'KHR' => ['name' => 'Riel',                  'code' => 116, 'fraction' => 2],
            'TWD' => ['name' => 'Dollar de Taiwan',      'code' => 901, 'fraction' => 2],
            'SEK' => ['name' => 'Couronne Suédoise',     'code' => 752, 'fraction' => 2],
            'DKK' => ['name' => 'Couronne Danoise',      'code' => 208, 'fraction' => 2],
            'KRW' => ['name' => 'Won',                   'code' => 410, 'fraction' => 0],
            'SGD' => ['name' => 'Dollar de Singapour',   'code' => 702, 'fraction' => 2],
            'XPF' => ['name' => 'Franc Polynésien',      'code' => 953, 'fraction' => 0],
            'XOF' => ['name' => 'Franc CFA',             'code' => 952, 'fraction' => 0],
        ];
    }
222045
public function getExchangeRate()
    {
        try {
            $currentCurrency = $this->storeManager->getStore()->getCurrentCurrency()->getCode();
            $baseCurrency = $this->storeManager->getStore()->getBaseCurrency()->getCode();
            return (float)$this->currencyFactory->create()->load($baseCurrency)->getAnyRate($currentCurrency);
        } catch (\Exception $e) {
            throw $e;
        }
    }
413767
public function loadAsXML()
    {
        $this->checkFileExists();
        $xml = new \DomDocument ();
        libxml_use_internal_errors(true);
        $result = $xml->load($this->absoluteFileName);
        if ($result) {
            return $xml;
        }
        $messageObject = ArrayUtil::getFromArray(libxml_get_errors(), 0);
        $libXMLMessage = ObjectUtil::getFromObject($messageObject, "message");
        $message = sprintf(self::EXCEPTION_INVALID_XML, $this->absoluteFileName, $libXMLMessage);
        $e = new \Exception(libxml_get_errors()[0]->message);
        libxml_clear_errors();
        throw $e;
    }
1347138
private function ConsumeNumber()
	{
		$tok = Token::IntegerLiteral;
		$sb = array();
		$this->BeginToken();
		// while ( XmlCharType.Instance.IsDigit( $this->Peek( 0 ) ) )
		while ( preg_match( "/^\d/", $this->Peek( 0 ) ) )
		{
			$sb[] = $this->Read();
		}
		if ( $this->Peek( 0 ) == '.' )
		{
			$tok = Token::DecimalLiteral;
			$sb[] = $this->Read();
			// while ( XmlCharType.Instance.IsDigit( $this->Peek( 0 ) ) )
			while ( preg_match( "/^\d/", $this->Peek( 0 ) ) )
			{
				$sb[] = $this->Read();
			}
		}
		$c = $this->Peek( 0 );
		if ( $c == 'E' || $c == 'e' )
		{
			$tok = Token::DoubleLiteral;
			$sb[] = $this->Read();
			$c = $this->Peek( 0 );
			if ( $c == '+' || $c == '-' )
			{
				$sb[] = $this->Read();
			}
		    // while ( XmlCharType.Instance.IsDigit( $this->Peek( 0 ) ) )
		    while ( preg_match( "/\d/",$this->Peek( 0 ) ) )
		    {
		    	$sb[] = $this->Read();
		    }
		}
		if ( preg_match( "/\p{L}/i", $this->Peek( 0 ) ) )
		{
			throw XPath2Exception::withErrorCodeAndParam( "XPST0003", Resources::XPST0003, "Expected a space" );
		}
		$this->EndToken();
		$s = implode( "", $sb );
		switch ( $tok )
		{
			case Token::IntegerLiteral:
				if ( ! is_int( $s + 0 ) )
				{
					throw new InvalidCastException( "The string literal cannot be converted to an integer: $s" );
				}

				// $this->ConsumeToken2( $tok, Integer::FromValue( $s ) );
				$this->ConsumeToken2( $tok, ( Integer )$s );
				break;

			case Token::DecimalLiteral:
				if ( strlen($s ) > 30)
				{
					throw new InvalidCastException( "The string literal converts to an number which is too large or too small for a decimal" );
				}
				$decimal = new DecimalValue( $s );
				// if ( is_infinite( $double ) && strtoupper( $s ) != "INF" )
				//	throw new InvalidCastException( "The string literal converts to an INF which is not valid" );
				$this->ConsumeToken2( $tok, $decimal );
				break;

			case Token::DoubleLiteral:
				if ( strlen($s ) > 308)
				{
					throw new InvalidCastException( "The string literal converts to an number which is too large or too small for a double" );
				}
				if ( ! is_numeric( $s ) )
				{
					throw XPath2Exception::withErrorCode( "XPST0003", Resources::FOCA0005 );
				}

				$double = doubleval( $s );
				// The number can be SO large that PHP converts the number to infinity which is not valid
				if ( is_infinite( $double ) && strtoupper( $s ) != "INF" )
				{
					throw new InvalidCastException( "The string literal converts to an INF which is not valid" );
				}
				$this->ConsumeToken2( $tok, $double );
				break;
		}
	}
92705
public function parse($value)
    {
        $locale = $this->params['locale'];
        //$formatterId = md5($locale);
        $formatterId = $locale;
        if (!array_key_exists($formatterId, $this->formatters)) {
            $this->loadFormatterId($formatterId);
        }
        // Currency will be passed as reference
        // setting it to null prevent eventual warning
        $currency = null;
        $result = $this->formatters[$formatterId]->parseCurrency($value, $currency);

        if ($result === false) {
            return null;
        }

        return ['value' => $result, 'currency' => $currency];
    }