ruwork / polyfill-form-dti-bundle
Symfony Form polyfill bundle adding input=datetime_immutable to date types.
Installs: 47 924
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.5
- ruwork/polyfill-form-dti: ^0.2@dev
- symfony/config: ^2.8 || ^3.0 || ^4.0
- symfony/dependency-injection: ^2.8 || ^3.0 || ^4.0
- symfony/form: ^2.8 || ^3.0 || ^4.0
- symfony/http-kernel: ^2.8 || ^3.0 || ^4.0
Requires (Dev)
- matthiasnoback/symfony-dependency-injection-test: ^1.2
- symfony/phpunit-bridge: ^2.8 || ^3.0 || ^4.0
This package is auto-updated.
Last update: 2023-07-12 04:31:08 UTC
README
This package is a polyfill bundle for my pull request adding input=datetime_immutable
option to the Symfony date and time form types.
Works with PHP >=5.5
and Symfony >=2.8
.
Internally this bundle uses the ruwork/polyfill-form-dti package and plugs its type extensions and guesser into DI with all necessary tags.
Installation
composer require ruwork/polyfill-form-dti-bundle
Enable the Ruwork\PolyfillFormDTIBundle\RuworkPolyfillFormDTIBundle
manually in your kernel if you don't use Symfony Flex.
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.
Testing
vendor/bin/simple-phpunit