Skip to content

Commit f97538b

Browse files
christian-kolbChristian Kolb
andauthored
Update to auto registration of doctrine types (#69)
Co-authored-by: Christian Kolb <info@digital-craftsman.de>
1 parent 2dca35b commit f97538b

20 files changed

+334
-207
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.13.0
4+
5+
- Updated registration to auto registration for doctrine types.
6+
- Deprecated previous doctrine types.
7+
38
## 0.12.0
49

510
- Added support for PHP 8.5.

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This Symfony bundle includes Symfony normalizers for automatic normalization and
2222

2323
As it's a central part of an application, it's tested thoroughly (including mutation testing). Currently, more than 80% of the lines of code in this repository are tests.
2424

25-
[![Latest Stable Version](https://img.shields.io/badge/stable-0.12.0-blue)](https://packagist.org/packages/digital-craftsman/date-time-precision)
25+
[![Latest Stable Version](https://img.shields.io/badge/stable-0.13.0-blue)](https://packagist.org/packages/digital-craftsman/date-time-precision)
2626
[![PHP Version Require](https://img.shields.io/badge/php-8.4|8.5-5b5d95)](https://packagist.org/packages/digital-craftsman/date-time-precision)
2727
[![codecov](https://codecov.io/gh/digital-craftsman-de/date-time-precision/branch/main/graph/badge.svg?token=vZ0IvKPj2f)](https://codecov.io/gh/digital-craftsman-de/date-time-precision)
2828
![Packagist Downloads](https://img.shields.io/packagist/dt/digital-craftsman/date-time-precision)
@@ -36,7 +36,7 @@ Install package through composer:
3636
composer require digital-craftsman/date-time-precision
3737
```
3838

39-
> ⚠️ This bundle can be used (and is being used) in production, but hasn't reached version 1.0 yet. Therefore, there will be breaking changes between minor versions. I'd recommend that you require the bundle only with the current minor version like `composer require digital-craftsman/date-time-precision:0.12.*`. Breaking changes are described in the releases and [the changelog](./CHANGELOG.md). Updates are described in the [upgrade guide](./UPGRADE.md).
39+
> ⚠️ This bundle can be used (and is being used) in production, but hasn't reached version 1.0 yet. Therefore, there will be breaking changes between minor versions. I'd recommend that you require the bundle only with the current minor version like `composer require digital-craftsman/date-time-precision:0.13.*`. Breaking changes are described in the releases and [the changelog](./CHANGELOG.md). Updates are described in the [upgrade guide](./UPGRADE.md).
4040
4141
## When would I need that?
4242

@@ -73,15 +73,33 @@ The resulting `$bookingsAllowedFrom` is still a date time with timezone `UTC` bu
7373
For the best code readability, it's best to use the `Moment` provided with the package as a full replacement for `\DateTime` or `\DateTimeImmutable` when you're speaking about a moment in time and the others value objects for the rest.
7474
The package integrates with the normalizers of `digital-craftsman/self-aware-normalizers` and provides Doctrine types (that use those interfaces) for `Moment` and all parts.
7575

76-
The Doctrine types are automatically registered with the bundle with the following type names:
76+
The value objects implement the relevant interfaces for the doctrine types and therefore can be used directly in your doctrine entities like the following:
7777

78-
- `dtp_moment`
79-
- `dtp_time`
80-
- `dtp_weekday`
81-
- `dtp_weekdays`
82-
- `dtp_date`
83-
- `dtp_month`
84-
- `dtp_year`
78+
```php
79+
<?php
80+
81+
declare(strict_types=1);
82+
83+
namespace App\Entity;
84+
85+
use DigitalCraftsman\DateTimePrecision\Moment;
86+
use Doctrine\ORM\Mapping as ORM;
87+
88+
#[ORM\Entity()]
89+
#[ORM\Table(name: 'facility')]
90+
class Facility
91+
{
92+
...
93+
94+
/** @psalm-readonly */
95+
#[ORM\Column(name: 'created_at', type: Moment::class)]
96+
public Moment $createdAt;
97+
98+
#[ORM\Column(name: 'updated_at', type: Moment::class)]
99+
public Moment $updatedAt;
100+
101+
...
102+
```
85103

86104
The package also contains a clock component consisting of the interface `Clock` with the two implementations `SystemClock` (for general use) and `FrozenClock` (for testing). The `SystemClock` will be autowired for the `Clock` and automatically replaced with `FrozenClock` in the test environment.
87105

UPGRADE.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
# Upgrade guide
22

3+
## From 0.12.* to 0.13.0
4+
5+
### Switch to automatic doctrine types
6+
7+
Use the full class string in the doctrine column `type` instead of the custom names.
8+
9+
Before:
10+
```php
11+
<?php
12+
13+
declare(strict_types=1);
14+
15+
namespace App\Entity;
16+
17+
use DigitalCraftsman\DateTimePrecision\Moment;
18+
use Doctrine\ORM\Mapping as ORM;
19+
20+
#[ORM\Entity()]
21+
#[ORM\Table(name: 'facility')]
22+
class Facility
23+
{
24+
...
25+
26+
/** @psalm-readonly */
27+
#[ORM\Column(name: 'created_at', type: 'dtp_moment')]
28+
public Moment $createdAt;
29+
30+
#[ORM\Column(name: 'updated_at', type: 'dtp_moment')]
31+
public Moment $updatedAt;
32+
33+
...
34+
```
35+
36+
After:
37+
```php
38+
<?php
39+
40+
declare(strict_types=1);
41+
42+
namespace App\Entity;
43+
44+
use DigitalCraftsman\DateTimePrecision\Moment;
45+
use Doctrine\ORM\Mapping as ORM;
46+
47+
#[ORM\Entity()]
48+
#[ORM\Table(name: 'facility')]
49+
class Facility
50+
{
51+
...
52+
53+
/** @psalm-readonly */
54+
#[ORM\Column(name: 'created_at', type: Moment::class)]
55+
public Moment $createdAt;
56+
57+
#[ORM\Column(name: 'updated_at', type: Moment::class)]
58+
public Moment $updatedAt;
59+
60+
...
61+
```
62+
363
## From 0.11.* to 0.12.0
464

565
### Dropped support for PHP 8.3

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "digital-craftsman/date-time-precision",
3-
"version": "0.12.0",
3+
"version": "0.13.0",
44
"description": "A Symfony bundle for more precise date and time handling through value objects",
55
"type": "symfony-bundle",
66
"require": {
77
"php": "8.4.*|8.5.*",
8-
"digital-craftsman/self-aware-normalizers": "^1.2.0",
8+
"digital-craftsman/self-aware-normalizers": "1.3.0",
99
"doctrine/dbal": "^4.4",
1010
"symfony/framework-bundle": "^7.4|^8.0",
1111
"symfony/serializer": "^7.4|^8.0"

0 commit comments

Comments
 (0)