本文整理汇总了PHP中Symfony\Component\Intl\Intl::getCurrencyBundle方法的典型用法代码示例。如果您正苦于以下问题:PHP Intl::getCurrencyBundle方法的具体用法?PHP Intl::getCurrencyBundle怎么用?PHP Intl::getCurrencyBundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Intl\Intl
的用法示例。
在下文中一共展示了Intl::getCurrencyBundle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: guard
/**
* @param string $value
*
* @throws InvalidCurrencyException
*/
protected function guard($value)
{
$currency = Intl::getCurrencyBundle()->getCurrencyName($value);
if (null === $currency) {
throw new InvalidCurrencyException($value);
}
}
示例2: loadChoiceList
/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
{
if (null !== $this->choiceList) {
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getCurrencyBundle()->getCurrencyNames()), $value);
}
示例3: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choices' => Intl::getCurrencyBundle()->getCurrencyNames(),
'choice_translation_domain' => false,
));
}
示例4: validate
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Currency) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Currency');
}
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
$value = (string) $value;
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
if (!isset($currencies[$value])) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Currency::NO_SUCH_CURRENCY_ERROR)
->addViolation();
} else {
$this->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Currency::NO_SUCH_CURRENCY_ERROR)
->addViolation();
}
}
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$textWriter = new TextBundleWriter();
$textWriter->write(CACHE_PATH . 'intl/text_bundle', 'en', ['data' => ['Ok']]);
$textWriter->write(CACHE_PATH . 'intl/text_bundle', 'ru', ['data' => ['Хорошо']]);
$phpWriter = new PhpBundleWriter();
$phpWriter->write(CACHE_PATH . 'intl/php_bundle', 'en', ['data' => 'php bundle: Ok', 'nested' => ['message' => 'Hi!']]);
$phpWriter = new PhpBundleWriter();
$phpWriter->write(CACHE_PATH . 'intl/php_bundle', 'ru', ['data' => 'php bundle: Хорошо', 'nested' => ['message' => 'Привет!']]);
$compiler = new GenrbCompiler();
$compiler->compile(CACHE_PATH . 'intl/text_bundle', CACHE_PATH . 'intl/compiled');
$phpReader = new PhpBundleReader();
$data = $phpReader->read(CACHE_PATH . 'intl/php_bundle', 'en');
$output->writeln($data['data']);
$data = $phpReader->read(CACHE_PATH . 'intl/php_bundle', 'ru');
$output->writeln($data['data']);
$reader = new BundleEntryReader($phpReader);
$data = $reader->readEntry(CACHE_PATH . 'intl/php_bundle', 'ru', ['nested', 'message']);
$output->writeln($data);
$language = Intl::getLanguageBundle()->getLanguageName('ru', 'RU', 'en');
$output->writeln($language);
$language = Intl::getLanguageBundle()->getLanguageName('ru', 'RU', 'de');
$output->writeln($language);
$language = Intl::getLanguageBundle()->getLanguageName('ru', 'RU', 'ru');
$output->writeln($language);
$currencyName = Intl::getCurrencyBundle()->getCurrencyName('RUB', 'en');
$output->writeln($currencyName);
$currencyName = Intl::getCurrencyBundle()->getCurrencySymbol('USD', 'en');
$output->writeln($currencyName);
$output->writeln('<comment>Ok</comment>');
}
示例6: getSettings
/**
* @return array
*/
public function getSettings()
{
$settings = $this->getYamlParameters();
$currency = new Setting();
$currency->setKey('currency')->setValue($settings['currency'])->setType('select2')->setOptions(Intl::getCurrencyBundle()->getCurrencyNames($settings['locale']));
$emailSettings = $this->getEmailSettings($settings);
return ['system' => ['general' => ['currency' => $currency]], 'email' => ['sending_options' => $emailSettings]];
}
示例7: getCurrencySymbol
public function getCurrencySymbol($currency = null)
{
$currency = $currency ?: $this->helper->getSettingsParameter($this->generalCurrencyKey);
if (array_key_exists($currency, $this->currencySymbols)) {
return $this->currencySymbols[$currency];
}
return SymfonyIntl::getCurrencyBundle()->getCurrencySymbol($currency);
}
示例8: __construct
/**
* @param float $value value
* @param string $currency currency
*/
public function __construct($value, $currency = 'EUR', $formatter = null)
{
$this->value = (double) $value;
$this->currency = strtoupper((string) $currency);
$this->fractionDigits = Intl::getCurrencyBundle()->getFractionDigits($currency);
if ($formatter) {
$this->setFormatter($formatter);
}
}
示例9: testValidChoiceList
public function testValidChoiceList()
{
$form = $this->factory->create(CurrencyType::class);
$validList = array_keys(Intl::getCurrencyBundle()->getCurrencyNames('en'));
sort($validList);
$choices = $form->getConfig()->getOption('choices');
sort($choices);
$this->assertSame($validList, $choices);
}
示例10: convertToCode
/**
* {@inheritdoc}
*/
public function convertToCode($name, $locale = 'en')
{
$names = Intl::getCurrencyBundle()->getCurrencyNames($locale);
$currencyCode = array_search($name, $names, true);
if (false === $currencyCode) {
throw new \InvalidArgumentException(sprintf('Currency "%s" not found! Available names: %s.', $name, implode(', ', $names)));
}
return $currencyCode;
}
示例11: convertToPHPValue
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (!array_key_exists($value, Intl::getCurrencyBundle()->getCurrencyNames())) {
throw new \RuntimeException(sprintf("'%d' is not a supported currency.", $value));
}
$currency = new Currency();
$currency->setLabel($value);
return $currency;
}
示例12: beforeCreateStub
/**
* {@inheritdoc}
*/
public function beforeCreateStub(StubbingContextInterface $context)
{
$currencies = array();
$currencyBundle = Intl::getCurrencyBundle();
foreach ($currencyBundle->getCurrencyNames('en') as $code => $name) {
$currencies[$code] = array(CurrencyBundle::INDEX_NAME => $name, CurrencyBundle::INDEX_SYMBOL => $currencyBundle->getCurrencySymbol($code, 'en'), CurrencyBundle::INDEX_FRACTION_DIGITS => $currencyBundle->getFractionDigits($code), CurrencyBundle::INDEX_ROUNDING_INCREMENT => $currencyBundle->getRoundingIncrement($code));
}
return array('Currencies' => $currencies);
}
示例13: installCurrencies
/**
* Installs the given currencies by codes.
*
* @param array $codes
*
* @throws \Exception
*/
public function installCurrencies($codes = array('USD'))
{
if (empty($codes)) {
throw new \Exception("Expected non empty array of currency codes.");
}
$currencyNames = Intl::getCurrencyBundle()->getCurrencyNames();
// TODO locale + sort by name
asort($currencyNames);
$this->generate(Currency::class, $currencyNames, $codes);
}
示例14: prepareCurrencies
private static function prepareCurrencies($locale)
{
self::$currencies = array();
self::$currenciesNames = array();
$bundle = Intl::getCurrencyBundle();
foreach ($bundle->getCurrencyNames($locale) as $currency => $name) {
self::$currencies[$currency] = array('name' => $name, 'symbol' => $bundle->getCurrencySymbol($currency, $locale), 'fractionDigits' => $bundle->getFractionDigits($currency), 'roundingIncrement' => $bundle->getRoundingIncrement($currency));
self::$currenciesNames[$currency] = $name;
}
}
示例15: submitDataProvider
/**
* @return array
*/
public function submitDataProvider()
{
$currencyBundle = Intl::getCurrencyBundle();
$usdName = $currencyBundle->getCurrencyName('USD');
$eurName = $currencyBundle->getCurrencyName('EUR');
$gbpName = $currencyBundle->getCurrencyName('GBP');
$rubName = $currencyBundle->getCurrencyName('RUB');
$uahName = $currencyBundle->getCurrencyName('UAH');
return ['full currency name and data from system config' => ['allowedCurrencies' => ['USD', 'UAH'], 'localeCurrency' => 'EUR', 'inputOptions' => [], 'expectedOptions' => ['compact' => false, 'choices' => ['USD' => $usdName, 'UAH' => $uahName]], 'submittedData' => 'UAH'], 'compact currency name and data from system config' => ['allowedCurrencies' => ['USD', 'UAH'], 'localeCurrency' => 'EUR', 'inputOptions' => ['compact' => true], 'expectedOptions' => ['compact' => true, 'choices' => ['USD' => 'USD', 'UAH' => 'UAH']], 'submittedData' => 'UAH'], 'full currency name and data from locale settings' => ['allowedCurrencies' => [], 'localeCurrency' => 'EUR', 'inputOptions' => ['compact' => false, 'currencies_list' => null], 'expectedOptions' => ['compact' => false, 'choices' => ['EUR' => $eurName]], 'submittedData' => 'EUR'], 'full currency name and data from currencies_list option' => ['allowedCurrencies' => ['USD', 'UAH'], 'localeCurrency' => 'EUR', 'inputOptions' => ['compact' => false, 'currencies_list' => ['RUB']], 'expectedOptions' => ['compact' => false, 'choices' => ['RUB' => $rubName]], 'submittedData' => 'RUB'], 'full currency name, data from system config and additional currencies' => ['allowedCurrencies' => ['USD', 'UAH'], 'localeCurrency' => 'EUR', 'inputOptions' => ['additional_currencies' => ['GBP']], 'expectedOptions' => ['compact' => false, 'choices' => ['GBP' => $gbpName, 'USD' => $usdName, 'UAH' => $uahName]], 'submittedData' => 'UAH'], 'compact currency name, data from currencies_list option and additional currencies' => ['allowedCurrencies' => ['USD', 'UAH'], 'localeCurrency' => 'EUR', 'inputOptions' => ['compact' => true, 'currencies_list' => ['RUB'], 'additional_currencies' => ['GBP']], 'expectedOptions' => ['compact' => true, 'choices' => ['GBP' => 'GBP', 'RUB' => 'RUB']], 'submittedData' => 'GBP'], 'full currencies list' => ['allowedCurrencies' => ['USD', 'UAH'], 'localeCurrency' => 'EUR', 'inputOptions' => ['full_currency_list' => true], 'expectedOptions' => ['full_currency_list' => true, 'choices' => $currencyBundle->getCurrencyNames('en')], 'submittedData' => 'GBP']];
}