Skip to content

Commit 255f584

Browse files
authored
Remove annotations support to gain Symfony 7 compatibility (#11)
This removes the annotation that has been deprecated in 1.4.0. Thus, we get rid of the `doctrine/annotations` dependency and the `annotation_reader` service, clearing the path towards Symfony 7 compatibility. The PHP 8.1 minimum requirement effectively limits usage with Symfony < 5.
1 parent 3efba6e commit 255f584

15 files changed

+104
-172
lines changed

.github/workflows/dependencies.yml

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
name: Dependencies
22

3-
permissions:
4-
contents: read
5-
63
on:
74
push:
85
branches:
96
- master
107
pull_request:
118

129
env:
13-
PHP_VERSION: 7.4
10+
PHP_VERSION: 8.1
1411

1512
jobs:
1613
composer-require-checker:
1714
name: Check missing composer requirements
18-
runs-on: ubuntu-20.04
15+
runs-on: ubuntu-22.04
1916
steps:
20-
- uses: shivammathur/setup-php@v2
17+
- uses: actions/checkout@v3
18+
- name: Konfiguriere PHP-Version und -Einstellungen im Worker-Node
19+
uses: shivammathur/setup-php@v2
2120
with:
2221
php-version: ${{ env.PHP_VERSION }}
2322
coverage: none
2423
tools: composer:v2
25-
- uses: actions/checkout@v3
26-
- uses: actions/cache@v3
24+
ini-values: variables_order=EGPCS, date.timezone=Europe/Berlin
25+
- name: Cache Composer Dependencies
26+
uses: actions/cache@v1
2727
with:
28-
path: vendor
29-
key: composer-${{ runner.os }}-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }}
28+
path: vendor/
29+
key: composer-${{ env.PHP_VERSION }}-${{ hashFiles('composer.*') }}
3030
restore-keys: |
31-
composer-${{ runner.os }}-${{ env.PHP_VERSION }}-
32-
composer-${{ runner.os }}-
31+
composer-${{ env.PHP_VERSION }}-${{ github.ref }}
32+
composer-${{ env.PHP_VERSION }}-
3333
- run: |
34-
composer install --no-interaction --no-progress --ansi --no-scripts
34+
composer install --no-interaction --no-scripts --no-progress --no-suggest
3535
composer show
36-
- uses: docker://webfactory/composer-require-checker:3.2.0
36+
- name: ComposerRequireChecker
37+
uses: docker://ghcr.io/webfactory/composer-require-checker:4.8.0

.github/workflows/fix-cs-php.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name: Coding Standards
99
jobs:
1010
open-pr-for-cs-violations:
1111
name: PHP-CS-Fixer
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1313
steps:
1414
- name: Checkout code
1515
uses: actions/checkout@v3
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
cat <<< $(jq --arg version $VERSION '.require |= with_entries(if ((.key|test("^symfony/"))) then .value=$version else . end)' < composer.json) > composer.json
3+
cat <<< $(jq --arg version $VERSION '.require |= with_entries(if ((.key|test("^symfony/deprecation-contracts")|not) and (.key|test("^symfony/"))) then .value=$version else . end)' < composer.json) > composer.json

.github/workflows/tests.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ env:
1111

1212
jobs:
1313
PHPUnit:
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-22.04
1515
strategy:
1616
fail-fast: false
1717
matrix:
1818
include:
19-
- { php-version: 7.2, symfony-locked-version: none, dependency-version: prefer-lowest }
20-
- { php-version: 7.4, symfony-locked-version: none, dependency-version: prefer-lowest }
21-
- { php-version: 7.4, symfony-locked-version: none, dependency-version: prefer-stable }
22-
- { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-stable }
19+
- { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-lowest }
20+
- { php-version: 8.2, symfony-locked-version: 6.4.*, dependency-version: prefer-stable }
21+
- { php-version: 8.3, symfony-locked-version: none, dependency-version: prefer-stable }
2322
name: PHPUnit (PHP ${{matrix.php-version}}, Symfony Version Lock ${{ matrix.symfony-locked-version }}, ${{ matrix.dependency-version }})
2423
steps:
2524
- uses: actions/checkout@v3

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ services:
144144
- @repository_post
145145
`
146146

147-
and note the service name to the Annotation:
147+
and put the service name into the attribute:
148148

149149
#[ReplaceWithNotModifiedResponse(["@app_caching_latest_posts"])]
150150

151-
To combine multiple LastModifiedDeterminators, simply add all of them to the annotation:
151+
To combine multiple LastModifiedDeterminators, simply add all of them to the attribute:
152152

153153
#[ReplaceWithNotModifiedResponse([
154154
"@app_caching_latest_posts",

UPGRADING.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade notes for `WebfactoryHttpCacheBundle`
22

3+
## Version 2.0.0
4+
5+
* Annotations support and the `\Webfactory\HttpCacheBundle\NotModified\Annotation\ReplaceWithNotModifiedResponse` class have been removed.
6+
37
## Version 1.4.0
48

59
* The `\Webfactory\HttpCacheBundle\NotModified\Annotation\ReplaceWithNotModifiedResponse` annotation has been deprecated. Use the

composer.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
],
2020

2121
"require": {
22-
"php": "^7.1|8.0.*|8.1.*",
23-
"doctrine/annotations": "^1.0",
24-
"symfony/config": "^4.4 | ^5.0 | ^6.0",
25-
"symfony/dependency-injection": "^4.4 | ^5.0 | ^6.0",
22+
"php": "^8.1",
23+
"symfony/config": "^5.0 | ^6.0 | ^7.0",
24+
"symfony/dependency-injection": "^5.0 | ^6.0 | ^7.0",
2625
"symfony/deprecation-contracts": "^2.0|^3.0",
27-
"symfony/http-foundation": "^4.4 | ^5.0 | ^6.0",
28-
"symfony/http-kernel": "^4.4 | ^5.0 | ^6.0"
26+
"symfony/http-foundation": "^5.0 | ^6.0 | ^7.0",
27+
"symfony/http-kernel": "^5.3 | ^6.0 | ^7.0"
2928
},
3029

3130
"require-dev": {
32-
"phpunit/phpunit": "^8.5|^9.0",
33-
"symfony/phpunit-bridge": "^5.0 | ^6.0"
31+
"phpunit/phpunit": "^9.6",
32+
"symfony/phpunit-bridge": "^6.0 | ^7.0"
3433
},
3534

3635
"suggest": {

src/DependencyInjection/WebfactoryHttpCacheExtension.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
88
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
99

10-
/**
11-
* Symfony Bundle Extension class.
12-
*/
1310
class WebfactoryHttpCacheExtension extends Extension
1411
{
15-
public function load(array $configs, ContainerBuilder $container)
12+
public function load(array $configs, ContainerBuilder $container): void
1613
{
1714
$locator = new FileLocator(__DIR__.'/../NotModified');
18-
$yamlLoader = new XmlFileLoader($container, $locator);
19-
$yamlLoader->load('services.xml');
15+
$loader = new XmlFileLoader($container, $locator);
16+
$loader->load('services.xml');
2017
}
2118
}

src/NotModified/Annotation/ReplaceWithNotModifiedResponse.php

-33
This file was deleted.

src/NotModified/Attribute/ReplaceWithNotModifiedResponse.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
* This attribute determines the latest last modified date over all of its LastModifiedDeterminators. This date is used
2121
* by the \Webfactory\HttpCacheBundle\NotModified\EventListener to possibly replace the execution of a controller with
2222
* sending a Not Modified HTTP response.
23-
*
24-
* @final
2523
*/
2624
#[Attribute(Attribute::TARGET_METHOD)]
27-
class ReplaceWithNotModifiedResponse
25+
final class ReplaceWithNotModifiedResponse
2826
{
2927
/** @var array */
3028
private $parameters;

src/NotModified/EventListener.php

+5-27
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99

1010
namespace Webfactory\HttpCacheBundle\NotModified;
1111

12-
use Doctrine\Common\Annotations\Reader;
1312
use ReflectionMethod;
1413
use SplObjectStorage;
1514
use Symfony\Component\DependencyInjection\ContainerInterface;
1615
use Symfony\Component\HttpFoundation\Response;
1716
use Symfony\Component\HttpKernel\Event\ControllerEvent;
1817
use Symfony\Component\HttpKernel\Event\ResponseEvent;
19-
use Webfactory\HttpCacheBundle\NotModified;
18+
use Webfactory\HttpCacheBundle\NotModified\Attribute\ReplaceWithNotModifiedResponse;
2019

2120
/**
2221
* Symfony EventListener for adding a "last modified" header to the response on the one hand. On the other hand, it
@@ -25,9 +24,6 @@
2524
*/
2625
final class EventListener
2726
{
28-
/** @var Reader */
29-
private $reader;
30-
3127
/** @var ContainerInterface */
3228
private $container;
3329

@@ -44,9 +40,8 @@ final class EventListener
4440
*/
4541
private $debug;
4642

47-
public function __construct(Reader $reader, ContainerInterface $container, bool $debug = false)
43+
public function __construct(ContainerInterface $container, bool $debug = false)
4844
{
49-
$this->reader = $reader;
5045
$this->container = $container;
5146
$this->lastModified = new SplObjectStorage();
5247
$this->debug = $debug;
@@ -107,7 +102,7 @@ public function onKernelResponse(ResponseEvent $event)
107102
/**
108103
* @param $controllerCallable callable PHP callback pointing to the method to reflect on.
109104
*
110-
* @return ReplaceWithNotModifiedResponse|null The annotation, if found. Null otherwise.
105+
* @return ?ReplaceWithNotModifiedResponse The annotation, if found. Null otherwise.
111106
*/
112107
private function findAnnotation(callable $controllerCallable)
113108
{
@@ -118,25 +113,8 @@ private function findAnnotation(callable $controllerCallable)
118113
[$class, $methodName] = $controllerCallable;
119114
$method = new ReflectionMethod($class, $methodName);
120115

121-
if (PHP_MAJOR_VERSION >= 8) {
122-
$attributes = $method->getAttributes(NotModified\Attribute\ReplaceWithNotModifiedResponse::class);
123-
124-
if ($attributes) {
125-
return $attributes[0]->newInstance();
126-
}
127-
}
128-
129-
/** @var ReplaceWithNotModifiedResponse|null $annotation */
130-
$annotation = $this->reader->getMethodAnnotation($method, NotModified\Annotation\ReplaceWithNotModifiedResponse::class);
131-
132-
if ($annotation) {
133-
trigger_deprecation(
134-
'webfactory/http-cache-bundle',
135-
'1.4.0',
136-
'Configuring webfactory/http-cache-bundle with annotations is deprecated, use attributes instead.'
137-
);
138-
}
116+
$attributes = $method->getAttributes(ReplaceWithNotModifiedResponse::class);
139117

140-
return $annotation;
118+
return $attributes ? $attributes[0]->newInstance() : null;
141119
}
142120
}

src/NotModified/services.xml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66
<services>
77
<service id="Webfactory\HttpCacheBundle\NotModified\EventListener" class="Webfactory\HttpCacheBundle\NotModified\EventListener" public="true">
8-
<argument type="service" id="annotation_reader" />
98
<argument type="service" id="service_container" />
109
<argument>%kernel.debug%</argument>
1110
<tag name="kernel.event_listener" event="kernel.controller" priority="-200" />

src/WebfactoryHttpCacheBundle.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
use Symfony\Component\HttpKernel\Bundle\Bundle;
66

7-
/**
8-
* Symfony Bundle class.
9-
*/
107
class WebfactoryHttpCacheBundle extends Bundle
118
{
129
}

0 commit comments

Comments
 (0)