Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/ruvents/ruwork-polyfill-form-dti
- Owner: ruvents
- License: mit
- Created: 2018-02-09T23:52:01.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-16T15:27:24.000Z (over 6 years ago)
- Last Synced: 2024-10-12T11:08:31.951Z (about 1 month ago)
- Topics: datetimeimmutable, forms, polyfill, symfony
- Language: PHP
- Homepage: http://symfony.com/blog/new-in-symfony-4-1-added-support-for-immutable-dates-in-forms
- Size: 28.3 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```