Skip to content

Commit d199870

Browse files
authored
Remove annotations support for full compatibility with symfony/framework-bundle ^7.0 (#40)
This PR is a breaking change that drops annotation support. This makes it possible to get rid of the `annotation_reader` Symfony DIC service dependency, truly clearing the path for Symfony 7.
1 parent 2edab6f commit d199870

File tree

8 files changed

+26
-85
lines changed

8 files changed

+26
-85
lines changed

.github/workflows/dependencies.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ on:
77
pull_request:
88

99
env:
10-
PHP_VERSION: 7.4
10+
PHP_VERSION: 8.1
1111

1212
jobs:
1313
composer-require-checker:
1414
name: Check missing composer requirements
15-
runs-on: ubuntu-20.04
15+
runs-on: ubuntu-22.04
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Konfiguriere PHP-Version und -Einstellungen im Worker-Node
@@ -35,4 +35,4 @@ jobs:
3535
composer require webfactory/http-cache-bundle
3636
composer show
3737
- name: ComposerRequireChecker
38-
uses: docker://webfactory/composer-require-checker:3.2.0
38+
uses: docker://ghcr.io/webfactory/composer-require-checker:4.8.0

.github/workflows/tests.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ env:
1313

1414
jobs:
1515
PHPUnit:
16-
runs-on: ubuntu-20.04
16+
runs-on: ubuntu-22.04
1717
strategy:
1818
fail-fast: false
1919
matrix:
2020
include:
21-
- { php-version: 7.2, symfony-locked-version: none, dependency-version: prefer-lowest }
22-
- { php-version: 7.4, symfony-locked-version: 4.4.*, dependency-version: prefer-stable }
23-
- { php-version: 7.4, symfony-locked-version: none, dependency-version: prefer-stable }
24-
- { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-stable }
21+
- { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-lowest }
22+
- { php-version: 8.2, symfony-locked-version: 6.4.*, dependency-version: prefer-stable }
23+
- { php-version: 8.3, symfony-locked-version: none, dependency-version: prefer-stable }
2524
name: PHPUnit (PHP ${{matrix.php-version}}, Symfony Version Lock ${{ matrix.symfony-locked-version }}, ${{ matrix.dependency-version }})
2625
steps:
2726
- uses: shivammathur/setup-php@v2
@@ -39,6 +38,6 @@ jobs:
3938
restore-keys: |
4039
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-locked-version }}-${{ matrix.dependency-version }}-
4140
- run: |
42-
composer install --no-interaction --no-progress --ansi --no-scripts
41+
composer update --${{ matrix.dependency-version }} --no-interaction --no-scripts --no-progress --ansi
4342
composer show
4443
- run: vendor/bin/phpunit

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## Version 4.0.0
2+
3+
* Annotation classes from the `\Webfactory\Bundle\WfdMetaBundle\Caching\Annotation` namespace have been removed, annotation support has been removed.
4+
Use attributes for configuration.
5+
6+
## Version 3.4.0
7+
8+
* Using annotations to configure caching is deprecated. A new `\Webfactory\Bundle\WfdMetaBundle\Caching\Attribute\Send304IfNotModified` attribute
9+
is provided to replace annotations-based configuration. Using this bundle for caching configuration remains a deprecated feature by itself.
10+
111
## Version 3.3.0
212

313
* Deprecate Send304IfNotModified annotation. Use WebfactoryHttpCachingBundle and its LastModifiedDeterminators instead. If in a hurry, @see \Webfactory\Bundle\WfdMetaBundle\Caching\WfdMetaQueries for a quick conversion.

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
],
1616

1717
"require": {
18-
"php": ">= 7.2, < 8.4",
19-
"doctrine/annotations": "^1.12",
18+
"php": ">= 8.1",
2019
"doctrine/dbal": "^2.12|^3.0",
2120
"doctrine/orm": "^2.0",
2221
"doctrine/persistence": "^1.3|^2.1",
@@ -39,8 +38,8 @@
3938
},
4039

4140
"require-dev": {
42-
"phpunit/phpunit": "^8.5",
43-
"symfony/phpunit-bridge": ">=5.0"
41+
"phpunit/phpunit": "^9.6.18",
42+
"symfony/phpunit-bridge": ">=7.0"
4443
},
4544

4645
"autoload": {

src/Caching/Annotation/Send304IfNotModified.php

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

src/Caching/Annotation/ValidUntilLastTouched.php

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

src/Caching/EventListener.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@
88

99
namespace Webfactory\Bundle\WfdMetaBundle\Caching;
1010

11-
use Doctrine\Common\Annotations\Reader;
1211
use ReflectionObject;
1312
use SplObjectStorage;
1413
use Symfony\Component\HttpFoundation\Response;
1514
use Symfony\Component\HttpKernel\Event\ControllerEvent;
1615
use Symfony\Component\HttpKernel\Event\ResponseEvent;
17-
use Webfactory\Bundle\WfdMetaBundle\Caching\Annotation\Send304IfNotModified;
16+
use Webfactory\Bundle\WfdMetaBundle\Caching\Attribute\Send304IfNotModified;
1817
use Webfactory\Bundle\WfdMetaBundle\MetaQueryFactory;
1918

2019
/**
2120
* @deprecated Use WebfactoryHttpCachingBundle instead.
2221
*/
2322
class EventListener
2423
{
25-
protected $reader;
26-
2724
/** @var MetaQueryFactory */
2825
protected $metaQueryFactory;
2926

@@ -32,9 +29,8 @@ class EventListener
3229
/** @var SplObjectStorage */
3330
protected $lastTouchedResults;
3431

35-
public function __construct(Reader $reader, MetaQueryFactory $metaQueryFactory, $debug)
32+
public function __construct(MetaQueryFactory $metaQueryFactory, $debug)
3633
{
37-
$this->reader = $reader;
3834
$this->metaQueryFactory = $metaQueryFactory;
3935
$this->debug = $debug;
4036
$this->lastTouchedResults = new SplObjectStorage();
@@ -93,10 +89,8 @@ public function onKernelResponse(ResponseEvent $event)
9389

9490
/**
9591
* @param $callback array A PHP callback (array) pointing to the method to reflect on.
96-
*
97-
* @return Send304IfNotModified|null The attribute, if found. Null otherwise.
9892
*/
99-
protected function findAttribute($callback): ?Attribute\Send304IfNotModified
93+
protected function findAttribute($callback): ?Send304IfNotModified
10094
{
10195
if (!\is_array($callback)) {
10296
return null;
@@ -105,22 +99,8 @@ protected function findAttribute($callback): ?Attribute\Send304IfNotModified
10599
$object = new ReflectionObject($callback[0]);
106100
$method = $object->getMethod($callback[1]);
107101

108-
if (\PHP_MAJOR_VERSION >= 8) {
109-
$attributes = $method->getAttributes(\Webfactory\Bundle\WfdMetaBundle\Caching\Attribute\Send304IfNotModified::class);
110-
111-
if ($attributes) {
112-
return $attributes[0]->newInstance();
113-
}
114-
}
115-
116-
foreach ($this->reader->getMethodAnnotations($method) as $configuration) {
117-
if ($configuration instanceof Send304IfNotModified) {
118-
@trigger_error(sprintf('Using annotations to configure wfd_meta based caching on %s::%s is deprecated, use attribute-based configuration instead.', $method->class, $method->name), \E_USER_DEPRECATED);
119-
120-
return $configuration;
121-
}
122-
}
102+
$attributes = $method->getAttributes(Send304IfNotModified::class);
123103

124-
return null;
104+
return $attributes ? $attributes[0]->newInstance() : null;
125105
}
126106
}

src/Resources/config/services.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
</service>
2323

2424
<service id="Webfactory\Bundle\WfdMetaBundle\Caching\EventListener">
25-
<argument type="service" id="annotation_reader" />
2625
<argument type="service" id="Webfactory\Bundle\WfdMetaBundle\MetaQueryFactory" />
2726
<argument>%kernel.debug%</argument>
2827

0 commit comments

Comments
 (0)