Skip to content

Commit 9d60a03

Browse files
Merge pull request #9 from andanteproject/version3-1
Support Symfony 8, add a Cache warmer on metadata, refactor metadata
2 parents 60bb1db + a90054b commit 9d60a03

File tree

57 files changed

+1936
-498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1936
-498
lines changed

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main", "develop" ]
6+
pull_request:
7+
branches: [ "main", "develop" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php-version: ['8.2', '8.4', '8.5']
15+
symfony-version: ['5.4.*', '6.4.*', '7.0.*', '8.0.*']
16+
doctrine-orm-version: ['2.20.*', '3.0.*']
17+
exclude:
18+
# Doctrine ORM 3.0 requires PHP 8.4+
19+
- php-version: '8.2'
20+
doctrine-orm-version: '3.0.*'
21+
# Symfony 8.0 requires PHP 8.4+
22+
- php-version: '8.2'
23+
symfony-version: '8.0.*'
24+
# Symfony 8 only works with doctrine-bundle 3.1+, which conflicts with ORM 2.x
25+
- symfony-version: '8.0.*'
26+
doctrine-orm-version: '2.20.*'
27+
28+
name: PHP ${{ matrix.php-version }} · SF ${{ matrix.symfony-version }} · Doctrine ORM ${{ matrix.doctrine-orm-version }}
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php-version }}
37+
extensions: mbstring, xml, ctype, iconv, intl, json, pdo_sqlite, sqlite3
38+
coverage: ${{ matrix.php-version == '8.5' && (matrix.symfony-version == '7.0.*' || matrix.symfony-version == '8.0.*') && matrix.doctrine-orm-version == '3.0.*' && 'pcov' || 'none' }}
39+
40+
- name: Constrain Symfony version
41+
run: |
42+
sed -ri 's/"symfony\/([^"]+)": "[^"]+"/"symfony\/\1": "${{ matrix.symfony-version }}"/g' composer.json
43+
# symfony/clock does not exist for 5.4 (added in 6.2); keep it installable on 5.4 jobs
44+
if [ "${{ matrix.symfony-version }}" = "5.4.*" ]; then
45+
sed -ri 's/"symfony\/clock": "[^"]+"/"symfony\/clock": "^6.2 | ^7.0"/' composer.json
46+
fi
47+
48+
- name: Constrain Doctrine ORM version
49+
run: |
50+
sed -ri 's/"doctrine\/orm": "[^"]+"/"doctrine\/orm": "${{ matrix.doctrine-orm-version }}"/' composer.json
51+
# Symfony 8 requires doctrine-bundle 3.1+, which requires doctrine/persistence ^4. ORM 3.0/3.1 only support persistence ^3. Use ORM 3.5.* (supports ^3.3.1 || ^4) for SF 8.
52+
if [ "${{ matrix.symfony-version }}" = "8.0.*" ] && [ "${{ matrix.doctrine-orm-version }}" = "3.0.*" ]; then
53+
sed -ri 's/"doctrine\/orm": "[^"]+"/"doctrine\/orm": "3.5.*"/' composer.json
54+
fi
55+
56+
- name: Install Composer dependencies
57+
uses: ramsey/composer-install@v3
58+
with:
59+
composer-options: "--prefer-dist --no-progress --no-interaction --optimize-autoloader"
60+
61+
- name: Run PHP-CS-Fixer
62+
if: matrix.php-version == '8.2' && matrix.symfony-version == '5.4.*' && matrix.doctrine-orm-version == '2.20.*'
63+
run: vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --using-cache=no
64+
65+
- name: Run PHPStan
66+
if: matrix.php-version == '8.5' && (matrix.symfony-version == '7.0.*' || matrix.symfony-version == '8.0.*') && matrix.doctrine-orm-version == '3.0.*'
67+
run: vendor/bin/phpstan analyse src tests --configuration=phpstan.neon --memory-limit=1G
68+
69+
- name: Run PHPUnit tests
70+
run: vendor/bin/phpunit ${{ matrix.php-version == '8.5' && (matrix.symfony-version == '7.0.*' || matrix.symfony-version == '8.0.*') && matrix.doctrine-orm-version == '3.0.*' && '--coverage-clover coverage.xml' || '' }}
71+
72+
- name: Upload coverage to Codecov
73+
if: matrix.php-version == '8.5' && (matrix.symfony-version == '7.0.*' || matrix.symfony-version == '8.0.*') && matrix.doctrine-orm-version == '3.0.*'
74+
uses: codecov/codecov-action@v4
75+
with:
76+
files: ./coverage.xml
77+
fail_ci_if_error: false

.github/workflows/workflow.yml

Lines changed: 0 additions & 62 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ composer.lock
1212
!bin/symfony_requirements
1313
/vendor/
1414
/phpunit.xml
15+
docker-compose.override.yml
16+
coverage.xml

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: setup php cs-fixer phpstan tests ci-local
2+
3+
setup:
4+
rm -f composer.lock
5+
docker-compose up --build -d php
6+
docker-compose exec php composer install
7+
8+
php:
9+
docker-compose exec php sh
10+
11+
cs-fixer:
12+
docker-compose exec php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes
13+
14+
phpstan:
15+
docker-compose exec php vendor/bin/phpstan analyse src tests --configuration=phpstan.neon --memory-limit=1G
16+
17+
tests:
18+
rm -rf var/cache/test
19+
mkdir -p var/cache/test
20+
docker-compose exec php vendor/bin/phpunit
21+
22+
ci-local:
23+
act -j build

README.md

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# Timestampable Bundle
33
#### Symfony Bundle - [AndanteProject](https://github.com/andanteproject)
44
[![Latest Version](https://img.shields.io/github/release/andanteproject/timestampable-bundle.svg)](https://github.com/andanteproject/timestampable-bundle/releases)
5-
![Github actions](https://github.com/andanteproject/timestampable-bundle/actions/workflows/workflow.yml/badge.svg?branch=main)
6-
![Framework](https://img.shields.io/badge/Symfony-4.x|5.x|6.x|7.x-informational?Style=flat&logo=symfony)
5+
![Github actions](https://github.com/andanteproject/timestampable-bundle/actions/workflows/ci.yml/badge.svg?branch=main)
6+
![Framework](https://img.shields.io/badge/Symfony-5.x|6.x|7.x|8.x-informational?Style=flat&logo=symfony)
77
![Php8](https://img.shields.io/badge/PHP-%208.x-informational?style=flat&logo=php)
8-
![PhpStan](https://img.shields.io/badge/PHPStan-Level%208-syccess?style=flat&logo=php)
8+
![PhpStan](https://img.shields.io/badge/PHPStan-Level%208-success?style=flat&logo=php)
99

10-
A Symfony Bundle to handle entities createdAt and updatedAt dates with Doctrine. 🕰
10+
A Symfony Bundle to handle entity `createdAt` and `updatedAt` dates with Doctrine. 🕰
1111

1212
## Requirements
13-
Symfony 4.x-7.x and PHP 8.2.
13+
Symfony 5.x–8.x and PHP 8.2.
1414

1515
## Install
1616
Via [Composer](https://getcomposer.org/):
@@ -19,27 +19,26 @@ $ composer require andanteproject/timestampable-bundle
1919
```
2020

2121
## Features
22-
- No configuration required to be ready to go but fully customizabile;
22+
- No configuration required to get started; fully customizable;
2323
- `createdAt` and `updatedAt` properties are `?\DateTimeImmutable`;
2424
- Uses [Symfony Clock](https://symfony.com/doc/current/components/clock.html);
2525
- Does not override your `createdAt` and `updatedAt` values when you set them explicitly;
26-
- No annotation/attributes required;
26+
- No annotations or attributes required;
2727
- Works like magic ✨.
2828

2929
## Basic usage
30-
After [install](#install), make sure you have the bundle registered in your symfony bundles list (`config/bundles.php`):
30+
After [install](#install), ensure the bundle is registered in your Symfony bundles list (`config/bundles.php`):
3131
```php
3232
return [
33-
/// bundles...
33+
// bundles...
3434
Andante\TimestampableBundle\AndanteTimestampableBundle::class => ['all' => true],
35-
/// bundles...
35+
// bundles...
3636
];
3737
```
38-
This should have been done automagically if you are using [Symfony Flex](https://flex.symfony.com). Otherwise, just register it by yourself.
38+
This is done automatically if you use [Symfony Flex](https://flex.symfony.com). Otherwise, register it manually.
3939

40-
41-
Let's suppose we have a `App\Entity\Article` doctrine entity we want to track created and update dates.
42-
All you have to do is to implement `Andante\TimestampableBundle\Timestampable\TimestampableInterface` and use `Andante\TimestampableBundle\Timestampable\TimestampableTrait` trait.
40+
Suppose you have an `App\Entity\Article` Doctrine entity and want to track created and updated dates.
41+
All you need to do is implement `Andante\TimestampableBundle\Timestampable\TimestampableInterface` and use the `Andante\TimestampableBundle\Timestampable\TimestampableTrait` trait.
4342

4443
```php
4544
<?php
@@ -75,26 +74,25 @@ class Article implements TimestampableInterface // <-- implement this
7574
}
7675

7776
// ...
78-
// Some others beautiful properties and methods ...
77+
// Other properties and methods ...
7978
// ...
8079
}
8180
```
82-
Make sure to update you database schema following your doctrine workflow (`bin/console doctrine:schema:update --force` if you are a badass devil guy or with a [migration](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.0/reference/introduction.html) if you choosed the be a better developer!).
81+
Update your database schema using your usual Doctrine workflow (e.g. `bin/console doctrine:schema:update --force`, or use [migrations](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.0/reference/introduction.html) for a safer approach).
8382

84-
You shoud see a new columns named `created_at` and `updated_at` ([can i change this?](#configuration-completely-optional)) or something similar based on your [doctrine naming strategy](https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/namingstrategy.html).
83+
You should see new columns named `created_at` and `updated_at` ([can I change this?](#configuration-completely-optional)), or similar names depending on your [Doctrine naming strategy](https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/namingstrategy.html).
8584

86-
#### Congrats! You're done! 🎉
85+
#### You're done! 🎉
8786

88-
Remember that `TimestampableInterface` and `TimestampableTrait` are shortcut to use `CreatedAtTimestampableInterface`+`CreatedAtTimestampableTrait` and `UpdatedAtTimestampableInterface`+`UpdatedAtTimestampableTrait` at the same time!
89-
If you need to track only **create date** or **update date** you can use these more specific interfaces!
87+
`TimestampableInterface` and `TimestampableTrait` are shortcuts that combine `CreatedAtTimestampableInterface` + `CreatedAtTimestampableTrait` and `UpdatedAtTimestampableInterface` + `UpdatedAtTimestampableTrait`. To track only **created** or **updated** dates, use the more specific interfaces and traits below.
9088

91-
| To keep track of | Implement interface | Use this Trait |
89+
| To track | Implement | Use trait |
9290
| --- | --- | --- |
93-
| **Create date** | `Andante\TimestampableBundle\Timestampable\CreatedAtTimestampableInterface` | `Andante\TimestampableBundle\Timestampable\CreatedAtTimestampableTrait` |
94-
| **Update date** | `Andante\TimestampableBundle\Timestampable\UpdatedAtTimestampableInterface` | `Andante\TimestampableBundle\Timestampable\UpdatedAtTimestampableTrait` |
95-
| **Both create and update dates** | `Andante\TimestampableBundle\Timestampable\TimestampableInterface` | `Andante\TimestampableBundle\Timestampable\TimestampableTrait` |
91+
| **Created date only** | `Andante\TimestampableBundle\Timestampable\CreatedAtTimestampableInterface` | `Andante\TimestampableBundle\Timestampable\CreatedAtTimestampableTrait` |
92+
| **Updated date only** | `Andante\TimestampableBundle\Timestampable\UpdatedAtTimestampableInterface` | `Andante\TimestampableBundle\Timestampable\UpdatedAtTimestampableTrait` |
93+
| **Both** | `Andante\TimestampableBundle\Timestampable\TimestampableInterface` | `Andante\TimestampableBundle\Timestampable\TimestampableTrait` |
9694

97-
## Usage with no trait
95+
## Usage without the trait
9896
```php
9997
<?php
10098

@@ -122,7 +120,7 @@ class Article implements TimestampableInterface // <-- implement this
122120
*/
123121
private string $title;
124122

125-
// DO NOT use ORM annotations to map these properties. See bundle configuration section for more info
123+
// DO NOT use ORM annotations to map these properties. See the configuration section for details.
126124
private ?\DateTimeImmutable $createdAt = null;
127125
private ?\DateTimeImmutable $updatedAt = null;
128126

@@ -152,32 +150,31 @@ class Article implements TimestampableInterface // <-- implement this
152150
}
153151
}
154152
```
155-
This allows you to, for instance, to have **a different name** for your properties (E.g. `created` instead of `createdAt` and `updated` instead of `updatedAt`).
156-
But you will need to explicit this in [bundle configuration](#configuration-completely-optional).
153+
This lets you use different property names (e.g. `created` and `updated` instead of `createdAt` and `updatedAt`). You must specify these in the [bundle configuration](#configuration-completely-optional).
157154

158155
## Configuration (completely optional)
159-
This bundle is build thinking how to save you time and follow best practices as close as possible.
156+
This bundle is built to save you time and follow best practices out of the box.
160157

161-
This means you can even ignore to have a `andante_timestampable.yml` config file in your application.
158+
You do not need an `andante_timestampable.yml` config file in your application.
162159

163-
However, for whatever reason (legacy code?), use the bundle configuration to change most of the behaviors as your needs.
160+
If you need to customize it (e.g. for legacy code), you can change most behavior via the bundle configuration:
164161
```yaml
165162
andante_timestampable:
166163
default:
167164
created_at_property_name: createdAt # default: createdAt
168-
# The property to be used by default as createdAt date inside entities
169-
# implementing CreatedAtTimestampableInterface or TimestampableInterface
165+
# Default property for createdAt in entities implementing
166+
# CreatedAtTimestampableInterface or TimestampableInterface
170167
updated_at_property_name: updatedAt # default: updatedAt
171-
# The property to be used by default as updatedAt date inside entities
172-
# implementing UpdatedAtTimestampableInterface or TimestampableInterface
173-
174-
created_at_column_name: created_at # default: null
175-
# Column name to be used on database for create date.
176-
# If set to NULL will use your default doctrine naming strategy
177-
updated_at_column_name: updated_at # default: null
178-
# Column name to be used on database for update date.
179-
# If set to NULL will use your default doctrine naming strategy
180-
entity: # You can use per-entity configuration to override default config
168+
# Default property for updatedAt in entities implementing
169+
# UpdatedAtTimestampableInterface or TimestampableInterface
170+
171+
created_at_column_name: created_at # default: null
172+
# Database column name for the created date.
173+
# If null, your Doctrine naming strategy is used
174+
updated_at_column_name: updated_at # default: null
175+
# Database column name for the updated date.
176+
# If null, your Doctrine naming strategy is used
177+
entity: # Per-entity overrides
181178
Andante\TimestampableBundle\Tests\Fixtures\Entity\Organization:
182179
created_at_property_name: createdAt
183180
Andante\TimestampableBundle\Tests\Fixtures\Entity\Address:
@@ -187,4 +184,4 @@ andante_timestampable:
187184
updated_at_column_name: updated_date
188185
```
189186
190-
Built with love ❤️ by [AndanteProject](https://github.com/andanteproject) team.
187+
Built with ❤️ by the [Andante Project](https://github.com/andanteproject) team.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828
],
2929
"require": {
3030
"php": "^8.2",
31-
"symfony/framework-bundle": "^5.0 | ^6.0 | ^7.0",
31+
"symfony/framework-bundle": "^5.0 | ^6.0 | ^7.0 | ^8.0",
3232
"doctrine/common": "^2.13 || ^3.0",
33+
"doctrine/doctrine-bundle": "^2.10 || ^3.0",
3334
"doctrine/event-manager": "^1.2 | ^2.0",
34-
"symfony/clock": "^6.2 | ^7.0"
35+
"doctrine/orm": "^2.15.3 || ^3.0",
36+
"symfony/clock": "^6.2 | ^7.0 | ^8.0"
3537
},
3638
"require-dev": {
3739
"ext-json": "*",
3840
"roave/security-advisories": "dev-master",
39-
"doctrine/orm": "^2.15.3",
4041
"phpunit/phpunit": "^9.5",
41-
"doctrine/doctrine-bundle": "^2.10",
4242
"phpstan/phpstan": "^1.2",
4343
"phpstan/phpstan-phpunit": "^1.0",
4444
"phpstan/extension-installer": "^1.1",

docker-compose.override.yml.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
php:
3+
environment:
4+
XDEBUG_MODE: develop,debug
5+
XDEBUG_CLIENT_HOST: host.docker.internal
6+
XDEBUG_CLIENT_PORT: 9090
7+
PHP_IDE_CONFIG: serverName=andanteproject-timestampable-bundle
8+
XDEBUG_START_WITH_REQUEST: yes

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
php:
3+
build:
4+
context: .
5+
dockerfile: docker/Dockerfile.php82
6+
volumes:
7+
- .:/var/www/html
8+
environment:
9+
XDEBUG_MODE: ${XDEBUG_MODE:-develop,debug}
10+
XDEBUG_CLIENT_HOST: ${XDEBUG_CLIENT_HOST:-host.docker.internal}
11+
XDEBUG_CLIENT_PORT: ${XDEBUG_CLIENT_PORT:-9090}
12+
PHP_IDE_CONFIG: ${PHP_IDE_CONFIG:-serverName=andanteproject-timestampable-bundle}
13+
XDEBUG_START_WITH_REQUEST: ${XDEBUG_START_WITH_REQUEST:-yes}

0 commit comments

Comments
 (0)