Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ruvents/ruwork-polyfill-form-dti

Symfony Form DateTimeImmutable Polyfill
https://github.com/ruvents/ruwork-polyfill-form-dti

datetimeimmutable forms polyfill symfony

Last synced: 5 days ago
JSON representation

Symfony Form DateTimeImmutable Polyfill

Awesome Lists containing this project

README

        

# Symfony Form DateTimeImmutable Polyfill

[![GitHub license](https://img.shields.io/github/license/ruvents/ruwork-polyfill-form-dti.svg?style=flat-square)](https://github.com/ruvents/ruwork-polyfill-form-dti/blob/master/LICENSE)
[![Travis branch](https://img.shields.io/travis/ruvents/ruwork-polyfill-form-dti/master.svg?style=flat-square)](https://travis-ci.org/ruvents/ruwork-polyfill-form-dti)
[![Codecov branch](https://img.shields.io/codecov/c/github/ruvents/ruwork-polyfill-form-dti/master.svg?style=flat-square)](https://codecov.io/gh/ruvents/ruwork-polyfill-form-dti)
[![Packagist](https://img.shields.io/packagist/v/ruwork/polyfill-form-dti.svg?style=flat-square)](https://packagist.org/packages/ruwork/polyfill-form-dti)

This package is a polyfill for my [pull request](http://symfony.com/blog/new-in-symfony-4-1-added-support-for-immutable-dates-in-forms) adding `input=datetime_immutable` option to the Symfony date and time form types.

Works with PHP `>=5.5` and Symfony `>=2.8`.

If you use Symfony Framework have a look at the corresponding [ruwork/polyfill-form-dti-bundle](https://github.com/ruvents/ruwork-polyfill-form-dti-bundle).

## Installation

```shell
composer require ruwork/polyfill-form-dti
```

## Usage

```php
addExtension(new DTIExtension())
// Optionally you can add a Doctrine ORM guesser
// to guess input=datetime_immutable for Doctrine 2.6 immutable date types.
->addTypeGuesser(new DoctrineOrmDTIGuesser($registry))
->getFormFactory();

$form = $factory
->createBuilder(FormType::class, [
'datetime' => new \DateTimeImmutable('1828-09-09 12:00:00'),
'date' => new \DateTimeImmutable('1860-01-29'),
'time' => new \DateTimeImmutable('23:59'),
])
->add('datetime', DateTimeType::class, [
'input' => 'datetime_immutable',
])
->add('date', DateType::class, [
'input' => 'datetime_immutable',
])
->add('time', TimeType::class, [
'input' => 'datetime_immutable',
])
->getForm();
```

## Testing

```shell
vendor/bin/simple-phpunit
```