예제 #1
0
 /**
  * @param string $value
  *
  * @throws InvalidCurrencyException
  */
 protected function guard($value)
 {
     $currency = Intl::getCurrencyBundle()->getCurrencyName($value);
     if (null === $currency) {
         throw new InvalidCurrencyException($value);
     }
 }
예제 #2
0
 /**
  * {@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
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(array(
         'choices' => Intl::getCurrencyBundle()->getCurrencyNames(),
         'choice_translation_domain' => false,
     ));
 }
예제 #4
0
    /**
     * {@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();
            }
        }
    }
 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
0
 /**
  * @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
0
 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
0
파일: Price.php 프로젝트: rezzza/accounting
 /**
  * @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);
     }
 }
 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
0
 /**
  * {@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;
 }
 /**
  * {@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;
 }
 /**
  * {@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
0
 /**
  * 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
0
 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;
     }
 }
 /**
  * @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']];
 }
예제 #16
0
 /**
  * {@inheritdoc}
  */
 protected function convertValue($value)
 {
     $data = $this->getBackendData($value);
     $prices = [];
     foreach ($data as $price) {
         if (isset($price['data']) && $price['data'] !== null) {
             $prices[] = $price['data'] . ' ' . Intl::getCurrencyBundle()->getCurrencySymbol($price['currency']);
         }
     }
     return implode(', ', $prices);
 }
예제 #17
0
 public function init()
 {
     parent::init();
     $this->options = array_merge(['type' => 'number', 'step' => '0.01', 'min' => 0], $this->options);
     Html::addCssClass($this->options, 'form-control');
     if (!$this->currencySymbol) {
         if (null === ($code = Yii::$app->formatter->currencyCode)) {
             $code = 'USD';
         }
         $this->currencySymbol = \Symfony\Component\Intl\Intl::getCurrencyBundle()->getCurrencySymbol($code);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function convertValue($value)
 {
     $data = $this->getBackendData($value);
     $prices = [];
     foreach ($data as $price) {
         if (isset($price['data']) && $price['data'] !== null) {
             $formattedPrice = $this->formatter->format($price['data']);
             $prices[] = sprintf('%s %s', $formattedPrice, Intl::getCurrencyBundle()->getCurrencySymbol($price['currency']));
         }
     }
     return implode(', ', $prices);
 }
 public function testGetPriceListCurrencyList()
 {
     /** @var PriceList $priceList */
     $priceList = $this->getReference('price_list_1');
     $this->client->request('GET', $this->getUrl('orob2b_pricing_price_list_currency_list', ['id' => $priceList->getId()]));
     $result = $this->client->getResponse();
     $this->assertJsonResponseStatusCodeEquals($result, 200);
     $data = json_decode($result->getContent(), true);
     $this->assertEquals($priceList->getCurrencies(), array_keys($data));
     $this->assertEquals(array_map(function ($currencyCode) {
         return Intl::getCurrencyBundle()->getCurrencyName($currencyCode);
     }, $priceList->getCurrencies()), array_values($data));
 }
예제 #20
0
 /**
  * {@inheritDoc}
  */
 public function validate($value, Constraint $constraint)
 {
     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])) {
         $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
     }
 }
예제 #21
0
 public function testSubmitData()
 {
     $faker = Factory::create();
     $formData = ['locale' => $faker->randomKey(Intl::getLocaleBundle()->getLocaleNames()), 'currency' => $faker->randomKey(Intl::getCurrencyBundle()->getCurrencyNames()), 'username' => $faker->userName, 'email_address' => $faker->email, 'base_url' => $faker->url, 'password' => null];
     $form = $this->factory->create(SystemInformationForm::class, null, ['userCount' => 0]);
     // submit the data to the form directly
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($formData, $form->getData());
     $view = $form->createView();
     $children = $view->children;
     foreach (array_keys($formData) as $key) {
         $this->assertArrayHasKey($key, $children);
     }
 }
예제 #22
0
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (extension_loaded('intl')) {
         $builder->add('locale', Select2::class, ['choices' => array_flip(Intl::getLocaleBundle()->getLocaleNames()), 'choices_as_values' => true, 'constraints' => new Constraints\NotBlank(['message' => 'Please select a locale']), 'placeholder' => 'Please select a locale']);
     } else {
         $builder->add('locale', null, ['data' => 'en', 'read_only' => true, 'help' => 'The only currently supported locale is "en". To choose a different locale, please install the \'intl\' extension', 'placeholder' => 'Please select a locale']);
     }
     $builder->add('currency', Select2::class, ['choices' => array_flip(Intl::getCurrencyBundle()->getCurrencyNames()), 'choices_as_values' => true, 'constraints' => new Constraints\NotBlank(['message' => 'Please select a currency']), 'placeholder' => 'Please select a currency']);
     $builder->add('base_url', null, ['constraints' => new Constraints\NotBlank(['message' => 'Please set the application base url'])]);
     if (0 === $options['userCount']) {
         $builder->add('username', null, ['constraints' => new Constraints\NotBlank(['message' => 'Please enter a username'])]);
         $builder->add('email_address', EmailType::class, ['constraints' => [new Constraints\NotBlank(['message' => 'Please enter a email']), new Constraints\Email()]]);
         $builder->add('password', RepeatedType::class, ['type' => PasswordType::class, 'invalid_message' => 'The password fields must match.', 'options' => ['attr' => ['class' => 'password-field']], 'required' => true, 'first_options' => ['label' => 'Password'], 'second_options' => ['label' => 'Repeat Password'], 'constraints' => [new Constraints\NotBlank(['message' => 'You must enter a secure password']), new Constraints\Length(['min' => 6])]]);
     }
 }
예제 #23
0
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $currencies = Intl::getCurrencyBundle()->getCurrencyNames();
     if (extension_loaded('intl')) {
         $builder->add('locale', 'select2', array('choices' => Intl::getLocaleBundle()->getLocaleNames(), 'constraints' => new Constraints\NotBlank(array('message' => 'Please select a locale')), 'placeholder' => '', 'choices_as_values' => false));
     } else {
         $builder->add('locale', null, array('data' => 'en', 'read_only' => true, 'help' => 'The only currently supported locale is "en". To choose a different locale, please install the \'intl\' extension'));
     }
     $builder->add('currency', 'select2', array('choices' => $currencies, 'constraints' => new Constraints\NotBlank(array('message' => 'Please select a currency')), 'placeholder' => '', 'choices_as_values' => false));
     $builder->add('base_url', null, array('constraints' => new Constraints\NotBlank(array('message' => 'Please set the application base url')), 'data' => $this->request->getSchemeAndHttpHost() . $this->request->getBaseUrl()));
     if (0 === $this->userCount) {
         $builder->add('username', null, array('constraints' => new Constraints\NotBlank(array('message' => 'Please enter a username'))));
         $builder->add('email_address', 'email', array('constraints' => array(new Constraints\NotBlank(array('message' => 'Please enter a email')), new Constraints\Email())));
         $builder->add('password', 'repeated', array('type' => 'password', 'invalid_message' => 'The password fields must match.', 'options' => array('attr' => array('class' => 'password-field')), 'required' => true, 'first_options' => array('label' => 'Password'), 'second_options' => array('label' => 'Repeat Password'), 'constraints' => array(new Constraints\NotBlank(array('message' => 'You must enter a secure password')), new Constraints\Length(array('min' => 6)))));
     }
 }
예제 #24
0
 public function testSubmitData()
 {
     $faker = Factory::create();
     $formData = array('locale' => $faker->randomKey(Intl::getLocaleBundle()->getLocaleNames()), 'currency' => $faker->randomKey(Intl::getCurrencyBundle()->getCurrencyNames()), 'username' => $faker->userName, 'email_address' => $faker->email, 'base_url' => $faker->url, 'password' => null);
     $type = new SystemInformationForm($this->getMock('Symfony\\Component\\HttpFoundation\\Request'));
     $form = $this->factory->create($type);
     // submit the data to the form directly
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($formData, $form->getData());
     $view = $form->createView();
     $children = $view->children;
     foreach (array_keys($formData) as $key) {
         $this->assertArrayHasKey($key, $children);
     }
 }
예제 #25
0
 public function construct_form()
 {
     \Stripe\Stripe::setApiKey($this->stripe_private_key);
     $stripe_account = \Stripe\Account::retrieve();
     $default_currency_symbol = \Symfony\Component\Intl\Intl::getCurrencyBundle()->getCurrencySymbol(strtoupper($stripe_account->default_currency));
     $plans = \Stripe\Plan::all(array("limit" => 10));
     if (empty($this->formTemplate) || !file_exists($this->formTemplate)) {
         $this->set_form_template('');
     }
     $wp_nonce_field = wp_nonce_field($this->nonce_id, '_wpnonce', true, false);
     $donate['defaults']['currency'] = $stripe_account->default_currency;
     $currencies = $stripe_account->currencies_supported;
     $index = array_search($stripe_account->default_currency, $currencies);
     array_splice($currencies, $index, 1);
     array_unshift($currencies, $stripe_account->default_currency);
     ob_start();
     include $this->formTemplate;
     $return = ob_get_contents();
     ob_end_clean();
     return $return;
 }
예제 #26
0
파일: Symbol.php 프로젝트: beggiatom/L5Intl
 /**
  * Viene utilizzato symfony in quanto NumberFormatter necessita del locale
  * completo (it_IT, en_US, en_GB)
  *
  * @param $currency | EUR, GBP
  * @return null|string
  */
 public function getCurrency($currency)
 {
     return SIntl::getCurrencyBundle()->getCurrencySymbol($currency, $this->locale);
 }
예제 #27
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function setupCurrencies(InputInterface $input, OutputInterface $output)
 {
     $currencyRepository = $this->get('sylius.repository.currency');
     $currencyManager = $this->get('sylius.manager.currency');
     $currencyFactory = $this->get('sylius.factory.currency');
     do {
         $currencies = $this->getCurrenciesCodes($input, $output);
         $valid = true;
         foreach ($currencies as $code) {
             if (0 !== count($errors = $this->validate(trim($code), array(new Currency())))) {
                 $valid = false;
             }
             $this->writeErrors($output, $errors);
         }
     } while (!$valid);
     foreach ($currencies as $key => $code) {
         $code = trim($code);
         $name = Intl::getCurrencyBundle()->getCurrencyName($code);
         $output->writeln(sprintf('Adding <info>%s</info>.', $name));
         if (null !== ($existingCurrency = $currencyRepository->findOneByCode($code))) {
             $this->currencies[] = $existingCurrency;
             continue;
         }
         $currency = $currencyFactory->createNew();
         $currency->setCode($code);
         $currency->setExchangeRate(1);
         $this->currencies[] = $currency;
         $currencyManager->persist($currency);
     }
     $currencyManager->flush();
 }
예제 #28
0
 /**
  * @When I change the currency to :currency
  */
 public function iChangeTheCurrencyTo($code)
 {
     $symbol = Intl::getCurrencyBundle()->getCurrencySymbol($code);
     $this->clickLink($symbol);
 }
 function it_provides_a_list_of_available_currency_labels_for_the_specified_locale()
 {
     $this->getCurrencyLabels()->shouldReturn(Intl\Intl::getCurrencyBundle()->getCurrencyNames('en'));
     $this->getCurrencyLabels('fr_FR')->shouldReturn(Intl\Intl::getCurrencyBundle()->getCurrencyNames('fr'));
 }
예제 #30
0
 /**
  * {@inheritdoc}
  */
 public function getCurrenciesToSelect()
 {
     return Intl::getCurrencyBundle()->getCurrencyNames();
 }