IntegerToLocalizedStringTransformer example

1234.6, '-1235', \NumberFormatter::ROUND_HALFDOWN],
            [-1234.5, '-1234', \NumberFormatter::ROUND_HALFDOWN],
            [-1234.4, '-1234', \NumberFormatter::ROUND_HALFDOWN],
        ];
    }

    /** * @dataProvider transformWithRoundingProvider */
    public function testTransformWithRounding($input$output$roundingMode)
    {
        $transformer = new IntegerToLocalizedStringTransformer(null, $roundingMode);

        $this->assertEquals($output$transformer->transform($input));
    }

    public function testReverseTransform()
    {
        // Since we test against "de_AT", we need the full implementation         IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('de_AT');

        
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class IntegerType extends AbstractType
{
    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping']$options['rounding_mode'], !$options['grouping'] ? 'en' : null));
    }

    /** * @return void */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        if ($options['grouping']) {
            $view->vars['type'] = 'text';
        }
    }

    
                        'empty_data' => $options['empty_data'][$part] ?? null,
                    ];
                    if ('choice' === $options['widget']) {
                        $childOptions['choice_translation_domain'] = false;
                        $childOptions['choices'] = $options[$part];
                        $childOptions['placeholder'] = $options['placeholder'][$part];
                    }
                    $childForm = $builder->create($part, self::WIDGETS[$options['widget']]$childOptions);
                    if ('integer' === $options['widget']) {
                        $childForm->addModelTransformer(
                            new ReversedTransformer(
                                new IntegerToLocalizedStringTransformer()
                            )
                        );
                    }
                    $builder->add($childForm);
                }
            }
            if ($options['with_invert']) {
                $builder->add('invert', CheckboxType::class[
                    'label' => $options['labels']['invert'],
                    'error_bubbling' => true,
                    'required' => false,
                    
Home | Imprint | This part of the site doesn't use cookies.