* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; class MoneyType extends AbstractType { protected static $patterns = array(); /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->addViewTransformer(new MoneyToLocalizedStringTransformer( $options['scale'], $options['grouping'], null, $options['divisor'] )) ; } /** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['money_pattern'] = self::getPattern($options['currency']); } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'scale' => 2, 'grouping' => false, 'divisor' => 1, 'currency' => 'EUR', 'compound' => false, )); $resolver->setAllowedTypes('scale', 'int'); } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'money'; } /** * Returns the pattern for this locale in UTF-8. * * The pattern contains the placeholder "{{ widget }}" where the HTML tag should * be inserted */ protected static function getPattern($currency) { if (!$currency) { return '{{ widget }}'; } $locale = \Locale::getDefault(); if (!isset(self::$patterns[$locale])) { self::$patterns[$locale] = array(); } if (!isset(self::$patterns[$locale][$currency])) { $format = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); $pattern = $format->formatCurrency('123', $currency); // the spacings between currency symbol and number are ignored, because // a single space leads to better readability in combination with input // fields // the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8) preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123(?:[,.]0+)?[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/u', $pattern, $matches); if (!empty($matches[1])) { self::$patterns[$locale][$currency] = $matches[1].' {{ widget }}'; } elseif (!empty($matches[2])) { self::$patterns[$locale][$currency] = '{{ widget }} '.$matches[2]; } else { self::$patterns[$locale][$currency] = '{{ widget }}'; } } return self::$patterns[$locale][$currency]; } } __halt_compiler();----SIGNATURE:----dqmLI1o6/Ewwed+ix+FqdIpBxvEqF3O5lfcMy5YWx7wh3klv0OsdCGgRq7QfpzDw9fTSHSg5faTbvl0D0ZuV9Q5Boecg1Ni9U/Thdw7KQGu86/doUINI1tYUuks3wN8rHcUkqPqQPUZNOuboX5C2bxqlWUaaEWEyW0yWDdbxMuBRi4/UVlLvfxus6bm2/NjqDn9Vh1pvlTSc8oyJ3QVlHChBjtabSH8y5l7Kdr7sMFVX1ExEbQA0wmgSI/WDNM/gzKD+QD6clWIyqwdMPlF+/h6k22T8AwOa87DZXWHwbRq1nEPYx86gMixwOuICzVpfTKZ8EfnNyaFclDZL5P76n5K6RwajBryyiZaEzQru/b5xkk+5c0CzTudr4VMx/M+jpB8wJEMMr/AEBCkurQdpC3yaeijbZXElHuxR5UACGhhqGlT5tZhog+7YfL29OsGAU7QErn36s/qZp28ToP2ZoapFn/3b9i89tfHQ5ylPgcPqOx5VPx0d+tWKzMtQTrsCOLk6e13z1wCd1nG2t8YNC+vreren3MLxVWnEv1X9cVVroYxHY73HXKFs3SPtnMK1eFE6EYw8VBv1O7wrkOQvrXlqOTmZku4nDZtCAjDlatEZyUNQDu3OWfw20vE9FU4LRPXDx40PVzTZs1KXqOP5QfyWejp25YlRSeAS0nh2jGU=----ATTACHMENT:----ODQ3OTM2ODQ0NTE0MDY2MCA0MzU1MTI1NDkxODcwNTU1IDk0NDk3MDQ3MTkyNTE3NTU=