2017 © Pedro Peláez
 

symfony-bundle polyfill-form-dti-bundle

Symfony Form polyfill bundle adding input=datetime_immutable to date types.

image

ruwork/polyfill-form-dti-bundle

Symfony Form polyfill bundle adding input=datetime_immutable to date types.

  • Friday, February 16, 2018
  • by RUVENTS
  • Repository
  • 4 Watchers
  • 1 Stars
  • 2,264 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 76 % Grown

The README.md

Symfony Form DateTimeImmutable Polyfill Bundle

GitHub license Travis branch Codecov branch Packagist, (*1)

This package is a polyfill bundle for my pull request adding input=datetime_immutable option to the Symfony date and time form types., (*2)

Works with PHP >=5.5 and Symfony >=2.8., (*3)

Internally this bundle uses the ruwork/polyfill-form-dti package and plugs its type extensions and guesser into DI with all necessary tags., (*4)

Installation

composer require ruwork/polyfill-form-dti-bundle

Enable the Ruwork\PolyfillFormDTIBundle\RuworkPolyfillFormDTIBundle manually in your kernel if you don't use Symfony Flex., (*5)

Usage

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @Entity
 */
class Survey
{
    /**
     * @ORM\Column(type="date_immutable")
     *
     * @var \DateTimeImmutable
     */
    private $dayOfBirth;

    public function getDayOfBirth()
    {
        return $this->dayOfBirth;
    }

    public function setDayOfBirth(\DateTimeImmutable $dayOfBirth)
    {
        $this->dayOfBirth = $dayOfBirth;
    }
}
<?php

namespace App\Controller;

use App\Entity\Survey;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\HttpFoundation\Request;

class FormController extends AbstractController
{
    /**
     * @Route("/form")
     * @Template
     */
    public function __invoke(Request $request)
    {
        $survey = new Survey();

        $form = $this->createFormBuilder($survey)
            ->add('dayOfBirth', DateType::class, [
                'input' => 'datetime_immutable',
            ])
            // or let the form guesser do the job for you
            ->add('dayOfBirth')
            ->getForm()
            ->handleRequest($request);

        return [
            'form' => $form->createView(),
        ];
    }
}

Bundle will automatically register the Ruwork\PolyfillFormDTI\Guesser\DoctrineOrmDTIGuesser if Doctrine DBAL's version is >=2.6 and @doctrine service is registered in DI., (*6)

Testing

vendor/bin/simple-phpunit

The Versions

16/02 2018
10/02 2018

0.1.0

0.1.0.0

Symfony Form polyfill bundle adding input=datetime_immutable to date types.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valentin Udaltsov

form bundle symfony polyfill