DateIntervalToArrayTransformer example

$builder->add($childForm);
                }
            }
            if ($options['with_invert']) {
                $builder->add('invert', CheckboxType::class[
                    'label' => $options['labels']['invert'],
                    'error_bubbling' => true,
                    'required' => false,
                    'translation_domain' => $options['translation_domain'],
                ]);
            }
            $builder->addViewTransformer(new DateIntervalToArrayTransformer($parts, 'text' === $options['widget']));
        }
        if ('string' === $options['input']) {
            $builder->addModelTransformer(
                new ReversedTransformer(
                    new DateIntervalToStringTransformer($format)
                )
            );
        } elseif ('array' === $options['input']) {
            $builder->addModelTransformer(
                new ReversedTransformer(
                    new DateIntervalToArrayTransformer($parts)
                )
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTransformer;

/** * @author Steffen Roßkamp <steffen.rosskamp@gimmickmedia.de> */
class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
{
    public function testTransform()
    {
        $transformer = new DateIntervalToArrayTransformer();
        $input = new \DateInterval('P1Y2M3DT4H5M6S');
        $output = [
            'years' => '1',
            'months' => '2',
            'days' => '3',
            'hours' => '4',
            'minutes' => '5',
            'seconds' => '6',
            'invert' => false,
        ];
        $this->assertSame($output$transformer->transform($input));
    }
Home | Imprint | This part of the site doesn't use cookies.