Skip to content

Commit 545658e

Browse files
John Quairiadbu
authored andcommitted
support symfony 7
* remove obsolete annotation support * document attributes * drop support for old php versions * adjust dependencies * fix codestyle
1 parent 0deeee9 commit 545658e

Some content is hidden

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

43 files changed

+196
-733
lines changed

.github/workflows/php.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ env:
55

66
on:
77
push:
8-
branches:
9-
- "*.x"
8+
branches:
9+
- "*.x"
1010
pull_request:
1111

1212
jobs:
@@ -17,25 +17,18 @@ jobs:
1717
matrix:
1818
include:
1919
# Test the latest stable release
20-
- php-version: '7.3'
21-
- php-version: '7.4'
22-
- php-version: '8.0'
2320
- php-version: '8.1'
2421
dependencies: 'jean-beru/fos-http-cache-cloudfront'
25-
- php-version: '7.4'
26-
symfony-version: '4.*'
27-
- php-version: '7.4'
28-
symfony-version: '5.*'
29-
- php-version: '8.0'
30-
symfony-version: '6.*'
22+
- php-version: '8.1'
23+
symfony-version: '6.4'
24+
- php-version: '8.2'
25+
symfony-version: '7.*'
26+
- php-version: '8.2'
27+
symfony-version: '6.4'
3128
# Minimum supported dependencies with the oldest PHP version
32-
- php-version: '7.3'
29+
- php-version: '8.1'
3330
composer-flag: '--prefer-stable --prefer-lowest'
34-
symfony-version: '4.4'
35-
# Test latest unreleased versions
36-
- php-version: '8.0'
37-
symfony-version: '6.*'
38-
stability: 'dev'
31+
symfony-version: '6.4'
3932
name: PHP ${{ matrix.php-version }} Test on Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}} ${{ matrix.stability }} ${{ matrix.composer-flag }}
4033
steps:
4134

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Changelog
44
3.x
55
===
66

7+
* Minimum PHP version is no 8.1
8+
* Support Symfony 6.4 and 7
9+
* Drop obsolete annotations support, use attributes
710
* Make `fastly` and `cloudflare` clients lazy loaded to support Symfony secrets that are only available at runtime, but
811
not yet when the container is built.
912

Resources/doc/reference/annotations.rst renamed to Resources/doc/reference/attributes.rst

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
Annotations
1+
Attributes
22
===========
33

4-
Annotate your controller actions to invalidate routes and paths when those
5-
actions are executed.
6-
7-
.. note::
8-
9-
Annotations need the SensioFrameworkExtraBundle including registering the
10-
Doctrine AnnotationsRegistry. Some features also need the
11-
ExpressionLanguage. Make sure to
12-
:ref:`install the dependencies first <requirements>`.
4+
Add attribute on your controller actions to invalidate routes and paths when those actions are executed.
135

146
.. _invalidatepath:
157

@@ -20,18 +12,6 @@ Invalidate a path::
2012

2113
use FOS\HttpCacheBundle\Configuration\InvalidatePath;
2214

23-
/**
24-
* @InvalidatePath("/articles")
25-
* @InvalidatePath("/articles/latest")
26-
*/
27-
public function editAction()
28-
{
29-
}
30-
31-
From PHP 8, you can replace the doctrine annotations by PHP attributes::
32-
33-
use FOS\HttpCacheBundle\Configuration\InvalidatePath;
34-
3515
#[InvalidatePath('/articles')]
3616
#[InvalidatePath('/articles/latest')]
3717
public function editAction()
@@ -49,15 +29,12 @@ See :doc:`/features/invalidation` for more information.
4929
``@InvalidateRoute``
5030
--------------------
5131

52-
Like InvalidatePath annotations, you can use PHP attributes instead if you are using PHP 8
5332
Invalidate a route with parameters::
5433

5534
use FOS\HttpCacheBundle\Configuration\InvalidateRoute;
5635

57-
/**
58-
* @InvalidateRoute("articles")
59-
* @InvalidateRoute("articles", params={"type" = "latest"})
60-
*/
36+
#[InvalidateRoute('articles')]
37+
#[InvalidateRoute('articles', params: ['type' => 'latest'])]
6138
public function editAction()
6239
{
6340
}
@@ -69,9 +46,9 @@ You can also use expressions_ in the route parameter values. This obviously
6946
:ref:`requires the ExpressionLanguage component <requirements>`. To invalidate
7047
route ``articles`` with the ``number`` parameter set to ``123``, do::
7148

72-
/**
73-
* @InvalidateRoute("articles", params={"number" = {"expression"="id"}})
74-
*/
49+
use FOS\HttpCacheBundle\Configuration\InvalidateRoute;
50+
51+
#[InvalidateRoute('articles', params: ['number' => ['expression' => 'id']])]
7552
public function editAction(Request $request, $id)
7653
{
7754
// Assume $request->attributes->get('id') returns 123
@@ -103,9 +80,9 @@ Like InvalidatePath annotations, you can use PHP attributes instead if you are u
10380

10481
Set/invalidate a tag::
10582

106-
/**
107-
* @Tag("news-article")
108-
*/
83+
use FOS\HttpCacheBundle\Configuration\Tag;
84+
85+
#[Tag('news-article')]
10986
public function showAction()
11087
{
11188
// ...
@@ -115,38 +92,37 @@ Set/invalidate a tag::
11592

11693
Multiple tags are possible::
11794

118-
/**
119-
* @Tag("news")
120-
* @Tag("news-list")
121-
*/
95+
use FOS\HttpCacheBundle\Configuration\Tag;
96+
97+
#[Tag('news')]
98+
#[Tag('news-list')]
12299
public function indexAction()
123100
{
124101
// ...
125102
}
126103

104+
127105
If you prefer, you can combine tags in one annotation::
128106

129-
/**
130-
* @Tag({"news", "news-list"})
131-
*/
107+
#[Tag(['news-article', 'news-list'])]
132108

133109
You can also use expressions_ in tags. This obviously
134110
:ref:`requires the ExpressionLanguage component <requirements>`. The following
135111
example sets the tag ``news-123`` on the Response::
136112

137-
/**
138-
* @Tag(expression="'news-'~id")
139-
*/
113+
use FOS\HttpCacheBundle\Configuration\Tag;
114+
115+
#[Tag(expression: "'news-'~id")]
140116
public function showAction($id)
141117
{
142118
// Assume request parameter $id equals 123
143119
}
144120

145121
Or, using a `param converter`_::
146122

147-
/**
148-
* @Tag(expression="'news-'~article.getId()")
149-
*/
123+
use FOS\HttpCacheBundle\Configuration\Tag;
124+
125+
#[Tag(expression: "'news-'~article.getId()")]
150126
public function showAction(Article $article)
151127
{
152128
// Assume $article->getId() returns 123

composer.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,33 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^7.3 || ^8.0",
25-
"friendsofsymfony/http-cache": "^2.15",
26-
"symfony/framework-bundle": "^4.4.0 || ^5.0 || ^6.0",
27-
"symfony/http-foundation": "^4.4.0 || ^5.0 || ^6.0",
28-
"symfony/http-kernel": "^4.4.0 || ^5.0 || ^6.0"
24+
"php": "^8.1",
25+
"friendsofsymfony/http-cache": "^2.15 || 3.x-dev",
26+
"symfony/framework-bundle": "^6.4 || ^7.0",
27+
"symfony/http-foundation": "^6.4 || ^7.0",
28+
"symfony/http-kernel": "^6.4 || ^7.0"
2929
},
3030
"require-dev": {
3131
"php-http/guzzle7-adapter": "^0.1.1",
3232
"php-http/message": "^1.0 || ^2.0",
3333
"php-http/httplug": "^2.2.0",
3434
"php-http/discovery": "^1.13",
3535
"guzzlehttp/guzzle": "^7.2",
36-
"mockery/mockery": "^1.3.2",
36+
"mockery/mockery": "^1.6.9",
3737
"monolog/monolog": "*",
38-
"sensio/framework-extra-bundle": "^4.0 || ^5.5.1 || ^6.0",
3938
"doctrine/annotations": "^1.11",
40-
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
41-
"symfony/console": "^4.4 || ^5.0 || ^6.0",
42-
"symfony/finder": "^4.4 || ^5.0 || ^6.0",
39+
"symfony/browser-kit": "^6.4 || ^7.0",
40+
"symfony/console": "^6.4 || ^7.0",
41+
"symfony/finder": "^6.4 || ^7.0",
4342
"phpunit/phpunit": "^9.6.15",
44-
"symfony/security-bundle": "^4.4 || ^5.0 || ^6.0",
45-
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
46-
"twig/twig": "^2.13",
47-
"symfony/yaml": "^4.4 || ^5.0 || ^6.0",
48-
"symfony/css-selector": "^4.4 || ^5.0 || ^6.0",
49-
"symfony/expression-language": "^4.4 || ^5.0 || ^6.0",
43+
"symfony/security-bundle": "^6.4 || ^7.0",
44+
"symfony/twig-bundle": "^6.4 || ^7.0",
45+
"twig/twig": "^v3.8",
46+
"symfony/yaml": "^6.4 || ^7.0",
47+
"symfony/css-selector": "^6.4 || ^7.0",
48+
"symfony/expression-language": "^6.4 || ^7.0",
5049
"symfony/monolog-bundle": "^3.0",
51-
"symfony/routing": "^4.4 || ^5.0 || ^6.0",
50+
"symfony/routing": "^6.4 || ^7.0",
5251
"matthiasnoback/symfony-config-test": "^4.3.0 || ^5.1",
5352
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0"
5453
},

src/Command/BaseInvalidateCommand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use FOS\HttpCacheBundle\CacheManager;
1515
use LogicException;
1616
use Symfony\Component\Console\Command\Command;
17-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1817
use Symfony\Component\DependencyInjection\ContainerInterface;
1918

2019
/**
@@ -24,8 +23,6 @@
2423
*/
2524
abstract class BaseInvalidateCommand extends Command
2625
{
27-
use ContainerAwareTrait;
28-
2926
/**
3027
* @var CacheManager
3128
*/

src/Configuration/InvalidatePath.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111

1212
namespace FOS\HttpCacheBundle\Configuration;
1313

14-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
15-
1614
/**
1715
* @Annotation
1816
*/
1917
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
20-
class InvalidatePath extends ConfigurationAnnotation
18+
class InvalidatePath
2119
{
2220
/**
2321
* @var array
@@ -34,7 +32,13 @@ public function __construct(
3432
$values = $data;
3533
}
3634

37-
parent::__construct($values);
35+
foreach ($values as $k => $v) {
36+
if (!method_exists($this, $name = 'set'.$k)) {
37+
throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, static::class));
38+
}
39+
40+
$this->$name($v);
41+
}
3842
}
3943

4044
/**
@@ -62,20 +66,4 @@ public function getPaths()
6266
{
6367
return $this->paths;
6468
}
65-
66-
/**
67-
* {@inheritdoc}
68-
*/
69-
public function getAliasName(): string
70-
{
71-
return 'invalidate_path';
72-
}
73-
74-
/**
75-
* {@inheritdoc}
76-
*/
77-
public function allowArray(): bool
78-
{
79-
return true;
80-
}
8169
}

src/Configuration/InvalidateRoute.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
namespace FOS\HttpCacheBundle\Configuration;
1313

14-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
1514
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1615
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1716

1817
/**
1918
* @Annotation
2019
*/
2120
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
22-
class InvalidateRoute extends ConfigurationAnnotation
21+
class InvalidateRoute
2322
{
2423
/**
2524
* @var string
@@ -44,7 +43,13 @@ public function __construct(
4443

4544
$values['params'] = $values['params'] ?? $params;
4645

47-
parent::__construct($values);
46+
foreach ($values as $k => $v) {
47+
if (!method_exists($this, $name = 'set'.$k)) {
48+
throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, static::class));
49+
}
50+
51+
$this->$name($v);
52+
}
4853
}
4954

5055
/**
@@ -111,20 +116,4 @@ public function getParams()
111116
{
112117
return $this->params;
113118
}
114-
115-
/**
116-
* {@inheritdoc}
117-
*/
118-
public function getAliasName(): string
119-
{
120-
return 'invalidate_route';
121-
}
122-
123-
/**
124-
* {@inheritdoc}
125-
*/
126-
public function allowArray(): bool
127-
{
128-
return true;
129-
}
130119
}

0 commit comments

Comments
 (0)