https://github.com/andanteproject/period-bundle
A Symfony Bundle to integrate thephpleague/period into Doctrine and Symfony Form
https://github.com/andanteproject/period-bundle
calendar collection date daterange datetime datetime-period datetime-range doctrine doctrine-orm doctrine-type doctrine-types interval period php query-builder range sequence symfony symfony-bundle symfony-form
Last synced: 5 months ago
JSON representation
A Symfony Bundle to integrate thephpleague/period into Doctrine and Symfony Form
- Host: GitHub
- URL: https://github.com/andanteproject/period-bundle
- Owner: andanteproject
- License: mit
- Created: 2021-04-08T09:05:24.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-01-31T14:23:11.000Z (about 2 years ago)
- Last Synced: 2025-08-18T18:40:00.195Z (6 months ago)
- Topics: calendar, collection, date, daterange, datetime, datetime-period, datetime-range, doctrine, doctrine-orm, doctrine-type, doctrine-types, interval, period, php, query-builder, range, sequence, symfony, symfony-bundle, symfony-form
- Language: PHP
- Homepage:
- Size: 73.2 KB
- Stars: 1
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Period Bundle
#### Symfony Bundle - [AndanteProject](https://github.com/andanteproject)
[](https://github.com/andanteproject/period-bundle/releases)




A Symfony Bundle to integrate [thephpleague/period](https://period.thephpleague.com)
into [Doctrine](https://github.com/doctrine/DoctrineBundle) and [Symfony Form](https://github.com/symfony/form).
## Requirements
Symfony 5.4-6.x and PHP 8.0.
## Install
Via [Composer](https://getcomposer.org/):
```bash
$ composer require andanteproject/period-bundle
```
## Features
- Persist `Period`, `Duration` and `Sequence` on your DB;
- Persist `Period` as a JSON field or
a [doctrine embeddable object](https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/tutorials/embeddables.html#separating-concerns-using-embeddables)
effortless (and it is allowed to be `null`!!).
- Doctrine DQL functions.
- Use `Period` in Symfony Forms its Form Type;
- Works like magic ✨.
## Basic usage
After [install](#install), make sure you have the bundle registered in your symfony bundles list (`config/bundles.php`):
```php
return [
/// bundles...
Andante\PeriodBundle\AndantePeriodBundle::class => ['all' => true],
/// bundles...
];
```
This should have been done automagically if you are using [Symfony Flex](https://flex.symfony.com). Otherwise, just
register it by yourself.
## Doctrine Mapping
The bundle is going to register `period`, `duration` and `sequence` doctrine types to allow you to map `Period`
, `Duration` and `Sequence` objects to the database.
```php
add('name', Type\TextType::class)
->add('period', PeriodType::class)
;
}
}
```
### PeriodType Options
#### default_boundary_type
**type**: `string` **default**: `[)`, allowed values: `[)`, `(]`, `()`, `[]`
which boundary type to be used if none has been selected via `boundary_type_choice`.
```php
$builder->add('period', PeriodType::class, [
'default_boundary_type' => '()',
]);
```
#### boundary_type_choice
**type**: `bool` **default**: `false`
Whether to include or not a `BoundaryTypeChoiceType` to let the user to choice the BoundaryType. This is `false` by
default. To change which boundary type should be use to create the `Period`, check out `default_boundary_type` option.
```php
$builder->add('period', PeriodType::class, [
'boundary_type_choice' => true,
]);
```
#### start_date_child_name
**type**: `string` **default**: `start`
How form child handling `startDate` property should be called.
```php
$builder->add('period', PeriodType::class, [
'start_date_child_name' => 'custom_start_date_form_child_name',
]);
```
#### end_date_child_name
**type**: `string` **default**: `end`
How form child handling `endDate` property should be called.
```php
$builder->add('period', PeriodType::class, [
'end_date_child_name' => 'custom_end_date_form_child_name',
]);
```
#### boundary_type_child_name
**type**: `string` **default**: `boundary`
```php
$builder->add('period', PeriodType::class, [
'boundary_type_child_name' => 'custom_boundary_type_form_child_name',
]);
```
How form child handling `boundaryType` property should be called.
#### start_date_form_type
**type**: `string` **default**: `Symfony\Component\Form\Extension\Core\Type\DateTimeType`
Which form type to be used for `startDate` property. You can replace it with something custom.
```php
use App\Form\MyDateTimeType;
$builder->add('period', PeriodType::class, [
'start_date_form_type' => MyDateTimeType::class,
]);
```
#### end_date_form_type
**type**: `string` **default**: `Symfony\Component\Form\Extension\Core\Type\DateTimeType`
Which form type to be used for `endDate` property. You can replace it with something custom.
```php
use App\Form\MyDateTimeType;
$builder->add('period', PeriodType::class, [
'end_date_form_type' => MyDateTimeType::class,
]);
```
#### start_date_options
**type**: `array` **default**: `[]`
Additional options to be used for the *startDate* form child.
```php
$builder->add('period', PeriodType::class, [
'start_date_options' => [
'label' => 'A different Label',
// + whatever option allowed by DateTimeType
],
]);
```
#### end_date_options
**type**: `array` **default**: `[]`
Additional options to be used for the *endDate* form child.
```php
$builder->add('period', PeriodType::class, [
'end_date_options' => [
'label' => 'A different Label',
// + whatever option allowed by DateTimeType
],
]);
```
#### boundary_type_options
**type**: `array` **default**: `[]`
Additional options to be used for the *boundaryType* form child.
```php
$builder->add('period', PeriodType::class, [
'boundary_type_options' => [
'label' => 'A different Label',
// + whatever option allowed by Andante\PeriodBundle\Form\BoundaryTypeChoiceType
],
]);
```
#### allow_null
**type**: `bool` **default**: `true`
Additional options to be used for the *boundaryType* form child.
```php
$builder->add('period', PeriodType::class, [
'allow_null' => false,
// Allow to trigger an error when your Period property is not nullable.
]);
```
## Configuration (completely optional)
This bundle is build thinking how to save you time and follow best practices as close as possible.
This means you can even ignore to have a `andante_period.yml` config file in your application.
However, for whatever reason, use the bundle configuration to change most of the behaviors as your needs.
```yaml
andante_period:
doctrine:
embedded_period:
default:
start_date_column_name: start_date # default: null
# Column name to be used on database for startDate property.
# If set to NULL will use your default doctrine naming strategy
end_date_column_name: end_date # default: null
# Column name to be used on database for endDate property.
# If set to NULL will use your default doctrine naming strategy
boundary_type_column_name: boundary_type # default: null
# Column name to be used on database for update boundaryType property.
# If set to NULL will use your default doctrine naming strategy
entity: # You can use per-entity configuration to override default config
App\Entity\Event:
start_date_column_name: starting_at
end_date_column_name: ending_at
App\Entity\Meeting:
start_date_column_name: start
end_date_column_name: end
```
Built with love ❤️ by [AndanteProject](https://github.com/andanteproject) team.