https://github.com/mapado/pretty-types
Pretty printed JSON related Doctrine DBAL types
https://github.com/mapado/pretty-types
Last synced: 4 months ago
JSON representation
Pretty printed JSON related Doctrine DBAL types
- Host: GitHub
- URL: https://github.com/mapado/pretty-types
- Owner: mapado
- License: mit
- Created: 2018-02-20T09:41:43.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-09-09T07:01:19.000Z (over 1 year ago)
- Last Synced: 2025-04-30T21:51:46.837Z (about 1 year ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Mapado pretty-types
- [Installation](#installation)
- Types:
- [JSON pretty](#json-pretty)
- [UTCDateTime](#utcdatetime)
- [License](#license)
## Installation
```sh
composer require mapado/pretty-types
```
## JSON pretty
Based on [`Doctrine DBAL types`](https://github.com/doctrine/dbal/tree/v2.10.0/lib/Doctrine/DBAL/Types).
Will store pretty printed JSON into database.
### Configuration
In your config file
```yaml
# Doctrine Configuration
doctrine:
dbal:
types:
json_pretty: Mapado\PrettyTypes\JsonPrettyType
```
### Usage
In your entities
```php
/**
* ...
*
* @ORM\Column(name="column_name", type="json_pretty")
*/
```
## UTCDateTime
If you want to store datetime in UTC in your database.
Copied version from [Working with DateTime Instances](https://www.doctrine-project.org/projects/doctrine-orm/en/3.2/cookbook/working-with-datetime.html#handling-different-timezones-with-the-datetime-type).
All credits goes to the doctrine team !
### Configuration
In your config file
```yaml
# Doctrine Configuration
doctrine:
dbal:
types:
datetime: Mapado\PrettyTypes\UTCDateTimeType
datetime_immutable: Mapado\PrettyTypes\UTCDateTimeImmutableType
datetimetz: Mapado\PrettyTypes\UTCDateTimeType
```
Be aware that this will override all datetimes configured with doctrine.
If you do not want to override everything and use a custom types instead:
```yaml
# Doctrine Configuration
doctrine:
dbal:
types:
utcdatetime: Mapado\PrettyTypes\UTCDateTimeType
utc_datetime_immutable: Mapado\PrettyTypes\UTCDateTimeImmutableType
```
### Usage
In your entities, if you overrode the default datetime types, Doctrine will implicitly use the new types for all datetime fields:
```php
#[ORM\Column]
private \DateTime $someDate;
#[ORM\Column]
private \DateTimeImmutable $someDate;
```
You should store the timezone next to the datetime too. Read [the doctrine documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/working-with-datetime.html) for more informations.
If you configured a custom type, use this instead:
```php
#[ORM\Column(type: 'utcdatetime')]
private \DateTime $someDate;
#[ORM\Column(type: 'utc_datetime_immutable')]
private \DateTimeImmutable $someDate;
```
## License
This project is licensed under the [MIT license](LICENSE).