Skip to content

Commit

Permalink
remove more annotation things
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Mar 20, 2024
1 parent 545658e commit 4347b53
Show file tree
Hide file tree
Showing 53 changed files with 471 additions and 798 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ jobs:
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: '8.1'
composer-flag: '--prefer-stable --prefer-lowest'
symfony-version: '6.4'
# Test latest unreleased versions
- 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
* 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
36 changes: 17 additions & 19 deletions Resources/doc/reference/attributes.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Attributes
===========

Add attribute on your controller actions to invalidate routes and paths when those actions are executed.
Add attributes on your controller actions to invalidate routes and paths when those actions are executed.

.. _invalidatepath:

``@InvalidatePath``
-------------------
``InvalidatePath``
------------------

Invalidate a path::

Expand All @@ -26,8 +26,8 @@ See :doc:`/features/invalidation` for more information.

.. _invalidateroute:

``@InvalidateRoute``
--------------------
``InvalidateRoute``
-------------------

Invalidate a route with parameters::

Expand All @@ -39,11 +39,11 @@ Invalidate a route with parameters::
{
}

Similarly to ``@InvalidatePath`` above, any successful response to an
Similarly to ``InvalidatePath`` above, any successful response to an
:term:`unsafe <safe>` request will invalidate the two routes.

You can also use expressions_ in the route parameter values. This obviously
:ref:`requires the ExpressionLanguage component <requirements>`. To invalidate
You can also use expressions_ in the route parameter values. To enable expression support, configure the
:ref:`ExpressionLanguage component <requirements>` of this bundle. To invalidate
route ``articles`` with the ``number`` parameter set to ``123``, do::

use FOS\HttpCacheBundle\Configuration\InvalidateRoute;
Expand All @@ -61,11 +61,11 @@ See :doc:`/features/invalidation` for more information.

.. _tag:

``@Tag``
--------
``Tag``
-------

You can make this bundle tag your response automatically using the ``@Tag``
annotation. :term:`Safe <safe>` operations like GET that produce a successful
You can make this bundle tag your response automatically using the ``Tag``
attribute. :term:`Safe <safe>` operations like GET that produce a successful
response will lead to that response being tagged; modifying operations like
POST, PUT, or DELETE will lead to the tags being invalidated.

Expand All @@ -76,8 +76,6 @@ HTTP header (``X-Cache-Tags``, by default).
Any non-safe request to the ``editAction`` that returns a successful response
will trigger invalidation of both the ``news`` and the ``news-123`` tags.

Like InvalidatePath annotations, you can use PHP attributes instead if you are using PHP 8

Set/invalidate a tag::

use FOS\HttpCacheBundle\Configuration\Tag;
Expand All @@ -102,12 +100,12 @@ Multiple tags are possible::
}


If you prefer, you can combine tags in one annotation::
If you prefer, you can combine tags in one attribute::

#[Tag(['news-article', 'news-list'])]

You can also use expressions_ in tags. This obviously
:ref:`requires the ExpressionLanguage component <requirements>`. The following
You can also use expressions_ in tags. To enable expression support, configure the
:ref:`ExpressionLanguage component <requirements>` of this bundle. The following
example sets the tag ``news-123`` on the Response::

use FOS\HttpCacheBundle\Configuration\Tag;
Expand All @@ -118,7 +116,7 @@ example sets the tag ``news-123`` on the Response::
// Assume request parameter $id equals 123
}

Or, using a `param converter`_::
Or, when using a `value resolver`_::

use FOS\HttpCacheBundle\Configuration\Tag;

Expand All @@ -132,4 +130,4 @@ See :doc:`/features/tagging` for an introduction to tagging.
If you wish to change the HTTP header used for storing tags, see
:doc:`/reference/configuration/tags`.

.. _param converter: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
.. _value resolver: https://symfony.com/doc/current/controller/value_resolver.html
7 changes: 3 additions & 4 deletions Resources/doc/reference/configuration/headers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ the request was matched.
Headers are **merged**. If the response already has certain cache directives
set, they are not overwritten. The configuration can thus specify defaults
that may be changed by controllers or services that handle the response, or
``@Cache`` annotations.
``Cache`` attributes.

The listener that applies the rules is triggered at priority 10, which
makes it handle before the ``@Cache`` annotations from the
SensioFrameworkExtraBundle are evaluated. Those annotations unconditionally
overwrite cache directives.
makes it handle before the ``Cache`` attributes from Symfony are evaluated.
Those attributes unconditionally overwrite cache directives.

The only exception is responses that *only* have the ``no-cache``
directive. This is the default value for the cache control and there is no
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/reference/configuration/invalidation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Configure invalidation to invalidate routes when some other routes are requested

.. include:: /includes/expression-language.rst

Your custom expression functions can then be used in the ``@InvalidateRoute`` :ref:`annotations<invalidateroute>`.
Your custom expression functions can then be used in the ``InvalidateRoute`` :ref:`attribute <invalidateroute>`.

.. code-block:: yaml
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/reference/configuration/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for an introduction. Also have a look at :doc:`configuring the proxy client for
lead to tagging being disabled. If you want to use tagging in one of those
cases, you need to explicitly enable tagging.

Enables tag annotations and rules. If you want to use tagging, it is recommended
Enables tag attributes and rules. If you want to use tagging, it is recommended
that you set this to ``true`` so you are notified of missing dependencies and
incompatible proxies:

Expand Down Expand Up @@ -47,7 +47,7 @@ HTTP header that tags are stored in.
.. include:: /includes/expression-language.rst

Your custom expression functions can then be used in both the ``tag_expressions``
section of the tag configuration and ``@tag`` :ref:`annotations<tag>`.
section of the tag configuration and ``Tag`` :ref:`attributes <tag>`.

.. code-block:: yaml
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"guzzlehttp/guzzle": "^7.2",
"mockery/mockery": "^1.6.9",
"monolog/monolog": "*",
"doctrine/annotations": "^1.11",
"symfony/browser-kit": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/finder": "^6.4 || ^7.0",
Expand Down
6 changes: 0 additions & 6 deletions src/Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class ClearCommand extends BaseInvalidateCommand
{
use PathSanityCheck;

/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
Expand All @@ -46,9 +43,6 @@ protected function configure(): void
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$cacheManager = $this->getCacheManager();
Expand Down
6 changes: 0 additions & 6 deletions src/Command/InvalidatePathCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public function __construct(CacheManager $cacheManager = null)
}
}

/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
Expand All @@ -67,9 +64,6 @@ protected function configure(): void
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$paths = $input->getArgument('paths');
Expand Down
Loading

0 comments on commit 4347b53

Please sign in to comment.