Skip to content

Commit

Permalink
remove annotation for 3.x release (#611)
Browse files Browse the repository at this point in the history
* support symfony 7

* remove obsolete annotation support
* document attributes
* drop support for old php versions
* adjust dependencies
* fix codestyle

* remove more annotation things

---------

Co-authored-by: John Quairia <john.quairia@stellar.io>
  • Loading branch information
dbu and John Quairia committed Mar 21, 2024
1 parent 0deeee9 commit a098964
Show file tree
Hide file tree
Showing 74 changed files with 637 additions and 1,500 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ env:

on:
push:
branches:
- "*.x"
branches:
- "*.x"
pull_request:

jobs:
Expand All @@ -17,25 +17,24 @@ jobs:
matrix:
include:
# Test the latest stable release
- php-version: '7.3'
- php-version: '7.4'
- php-version: '8.0'
- php-version: '8.1'
dependencies: 'jean-beru/fos-http-cache-cloudfront'
- php-version: '7.4'
symfony-version: '4.*'
- php-version: '7.4'
symfony-version: '5.*'
- php-version: '8.0'
symfony-version: '6.*'
- php-version: '8.1'
symfony-version: '6.4'
- php-version: '8.2'
symfony-version: '7.*'
- php-version: '8.3'
symfony-version: '7.*'
- php-version: '8.2'
symfony-version: '6.4'
# Minimum supported dependencies with the oldest PHP version
- php-version: '7.3'
- php-version: '8.1'
composer-flag: '--prefer-stable --prefer-lowest'
symfony-version: '4.4'
symfony-version: '6.4'
# Test latest unreleased versions
- php-version: '8.0'
symfony-version: '6.*'
- php-version: '8.3'
stability: 'dev'

name: PHP ${{ matrix.php-version }} Test on Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}} ${{ matrix.stability }} ${{ matrix.composer-flag }}
steps:

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
3.x
===

* Minimum PHP version is no 8.1
* Support Symfony 6.4 and 7
* Drop obsolete annotations support, use attributes
Remove all configuration you have at `fos_http_cache.tags.annotations`
* Make `fastly` and `cloudflare` clients lazy loaded to support Symfony secrets that are only available at runtime, but
not yet when the container is built.

Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/features/headers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Caching Headers

You can configure HTTP caching headers based on request and response properties.
This configuration approach is more convenient than `manually setting cache headers`_
and an alternative to `setting caching headers through annotations`_.
and an alternative to `setting caching headers through attributes`_.

Set caching headers under the ``cache_control`` configuration section,
which consists of a set of rules. When the request matches all criteria under
Expand Down Expand Up @@ -70,4 +70,4 @@ This is an example configuration. For more, see the
etag: "strong"
.. _manually setting cache headers: https://symfony.com/doc/current/http_cache.html#the-cache-control-header
.. _setting caching headers through annotations: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html
.. _setting caching headers through attributes: https://symfony.com/doc/current/http_cache.html#making-your-responses-http-cacheable
19 changes: 9 additions & 10 deletions Resources/doc/features/invalidation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,24 @@ returns a successful response, both routes ``villains_index`` and
``villain_details`` will be purged. See the
:doc:`/reference/configuration/invalidation` configuration reference.

Annotations
-----------
Attributes
----------

Set the ``@InvalidatePath`` and ``@InvalidateRoute`` annotations to trigger
Set the ``InvalidatePath`` and ``InvalidateRoute`` attributes to trigger
invalidation from your controllers::

use FOS\HttpCacheBundle\Configuration\InvalidatePath;
use Symfony\Component\ExpressionLanguage\Expression;

/**
* @InvalidatePath("/articles")
* @InvalidatePath("/articles/latest")
* @InvalidateRoute("overview", params={"type" = "latest"})")
* @InvalidateRoute("detail", params={"id" = {"expression"="id"}})")
*/
#[InvalidatePath('/articles')]
#[InvalidatePath('/articles/latest')]
#[InvalidateRoute('overview', params: ['type' => 'latest'])]
#[InvalidateRoute("detail", params: ['id' => new Expression('my-expression="id"')])]
public function editAction($id)
{
}

See the :doc:`/reference/annotations` reference.
See the :doc:`/reference/attributes` reference.

Console Commands
----------------
Expand Down
17 changes: 8 additions & 9 deletions Resources/doc/features/tagging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ You can tag responses in different ways:
* From PHP code by using the response tagger to set tags and the cache manager
to invalidate tags;
* Set tags from twig templates with a function;
* In project configuration or using annotations on controller actions.
* In project configuration or using attributes on controller actions.

You can add tags before the response object exists. The tags are automatically
added to the response by a listener. The listener also detects pending tag
Expand Down Expand Up @@ -149,19 +149,18 @@ Now if a :term:`safe` request matches the criteria under ``match``, the response
will be tagged with ``news``. When an unsafe request matches, the tag ``news``
will be invalidated.

Tagging and Invalidating with Controller Annotations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tagging and Invalidating with Controller Attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the ``@Tag`` annotations to your controllers to set and invalidate tags::
Add the ``Tag`` attribute to your controllers to set and invalidate tags::

use FOS\HttpCacheBundle\Configuration\Tag;
use Symfony\Component\ExpressionLanguage\Expression;

class NewsController
{
/**
* @Tag("news", expression="'news-'~id")
*/
public function articleAction($id)
#[Tag('news', expression: new Expression('"news-"~id'))]
public function articleAction(string $id)
{
// Assume $id equals 123
}
Expand All @@ -172,7 +171,7 @@ on the response. If a client tries to update or delete news article 123 with an
unsafe request to ``articleAction``, such as POST or DELETE, tag ``news-123``
is invalidated.

See the :ref:`@Tag reference <tag>` for full details.
See the :ref:`Tag reference <tag>` for full details.

.. _Tagged Cache Invalidation: http://blog.kevburnsjr.com/tagged-cache-invalidation
.. _Linked Cache Invalidation: http://tools.ietf.org/html/draft-nottingham-linked-cache-inv-03
Expand Down
45 changes: 9 additions & 36 deletions Resources/doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,14 @@ For most features, you also need to :ref:`configure a caching proxy <foshttpcach

.. _requirements:

Requirements
------------

SensioFrameworkExtraBundle
~~~~~~~~~~~~~~~~~~~~~~~~~~

If you want to use this bundle’s annotations, install the
SensioFrameworkExtraBundle_:

.. code-block:: bash
$ composer require sensio/framework-extra-bundle
And , if you don't use a recent version of Symfony, include it in your project::

<?php
// app/AppKernel.php

public function registerBundles()
{
$bundles = array(
// ...
new FOS\HttpCacheBundle\FOSHttpCacheBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
// ...
);

.. _expression language requirement:
Optional Dependencies
---------------------

ExpressionLanguage
~~~~~~~~~~~~~~~~~~

If you wish to use expressions_ in your annotations , you also need Symfony’s
ExpressionLanguage_ component. If you’re not using full-stack Symfony 2.4 or
later, you need to explicitly add the component:
If you wish to use expressions_ in your :ref:`attributes <reference/attributes.rst>`,
you need Symfony’s ExpressionLanguage_ component. Make sure it is part of your application with:

.. code-block:: bash
Expand All @@ -92,10 +65,10 @@ Functionality
This table shows where you can find specific functions.

========================= ==================================== ==================================================== ==============================================
Functionality Annotations Configuration Manually
Functionality Attributes Configuration Manually
========================= ==================================== ==================================================== ==============================================
Set Cache-Control headers (SensioFrameworkExtraBundle_) :doc:`rules <reference/configuration/headers>` (Symfony_)
Tag and invalidate :doc:`@Tag </features/tagging>` :doc:`rules <reference/configuration/headers>` :doc:`cache manager <reference/cache-manager>`
Set Cache-Control headers (`Symfony cache attributes`_) :doc:`rules <reference/configuration/headers>` (`Symfony cache control`_)
Tag and invalidate :doc:`#[Tag] </features/tagging>` :doc:`rules <reference/configuration/tags>` :doc:`cache manager <reference/cache-manager>`
Invalidate routes :ref:`invalidateroute` :ref:`invalidators <invalidation configuration>` :doc:`cache manager <reference/cache-manager>`
Invalidate paths :ref:`invalidatepath` :ref:`invalidators <invalidation configuration>` :doc:`cache manager <reference/cache-manager>`
========================= ==================================== ==================================================== ==============================================
Expand All @@ -109,7 +82,7 @@ This bundle is released under the MIT license.
:language: none

.. _Packagist: https://packagist.org/packages/friendsofsymfony/http-cache-bundle
.. _SensioFrameworkExtraBundle: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
.. _ExpressionLanguage: https://symfony.com/doc/current/components/expression_language.html
.. _Symfony: https://symfony.com/doc/current/http_cache.html#the-cache-control-header
.. _Symfony cache attributes: https://symfony.com/doc/current/http_cache.html#making-your-responses-http-cacheable
.. _Symfony cache control: https://symfony.com/doc/current/http_cache.html#the-cache-control-header
.. _client implementations: https://packagist.org/providers/php-http/client-implementation
4 changes: 2 additions & 2 deletions Resources/doc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Reference
=========

This part is a full description of all available configuration options,
annotations and public methods.
attributes and public methods.

.. toctree::
:maxdepth: 2

reference/configuration
reference/annotations
reference/attributes
reference/cache-manager
reference/glossary
Loading

0 comments on commit a098964

Please sign in to comment.