Skip to content

remove annotation for 3.X release #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 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,18 @@ 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.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'
# Test latest unreleased versions
- php-version: '8.0'
symfony-version: '6.*'
stability: 'dev'
symfony-version: '6.4'
name: PHP ${{ matrix.php-version }} Test on Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}} ${{ matrix.stability }} ${{ matrix.composer-flag }}
steps:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
Annotations
Attributes
===========

Annotate your controller actions to invalidate routes and paths when those
actions are executed.

.. note::

Annotations need the SensioFrameworkExtraBundle including registering the
Doctrine AnnotationsRegistry. Some features also need the
ExpressionLanguage. Make sure to
:ref:`install the dependencies first <requirements>`.
Add attribute on your controller actions to invalidate routes and paths when those actions are executed.

.. _invalidatepath:

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

use FOS\HttpCacheBundle\Configuration\InvalidatePath;

/**
* @InvalidatePath("/articles")
* @InvalidatePath("/articles/latest")
*/
public function editAction()
{
}

From PHP 8, you can replace the doctrine annotations by PHP attributes::

use FOS\HttpCacheBundle\Configuration\InvalidatePath;

#[InvalidatePath('/articles')]
#[InvalidatePath('/articles/latest')]
public function editAction()
Expand All @@ -49,15 +29,12 @@ See :doc:`/features/invalidation` for more information.
``@InvalidateRoute``
--------------------

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

use FOS\HttpCacheBundle\Configuration\InvalidateRoute;

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

/**
* @InvalidateRoute("articles", params={"number" = {"expression"="id"}})
*/
use FOS\HttpCacheBundle\Configuration\InvalidateRoute;

#[InvalidateRoute('articles', params: ['number' => ['expression' => 'id']])]
public function editAction(Request $request, $id)
{
// Assume $request->attributes->get('id') returns 123
Expand Down Expand Up @@ -103,9 +80,9 @@ Like InvalidatePath annotations, you can use PHP attributes instead if you are u

Set/invalidate a tag::

/**
* @Tag("news-article")
*/
use FOS\HttpCacheBundle\Configuration\Tag;

#[Tag('news-article')]
public function showAction()
{
// ...
Expand All @@ -115,38 +92,37 @@ Set/invalidate a tag::

Multiple tags are possible::

/**
* @Tag("news")
* @Tag("news-list")
*/
use FOS\HttpCacheBundle\Configuration\Tag;

#[Tag('news')]
#[Tag('news-list')]
public function indexAction()
{
// ...
}


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

/**
* @Tag({"news", "news-list"})
*/
#[Tag(['news-article', 'news-list'])]

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

/**
* @Tag(expression="'news-'~id")
*/
use FOS\HttpCacheBundle\Configuration\Tag;

#[Tag(expression: "'news-'~id")]
public function showAction($id)
{
// Assume request parameter $id equals 123
}

Or, using a `param converter`_::

/**
* @Tag(expression="'news-'~article.getId()")
*/
use FOS\HttpCacheBundle\Configuration\Tag;

#[Tag(expression: "'news-'~article.getId()")]
public function showAction(Article $article)
{
// Assume $article->getId() returns 123
Expand Down
33 changes: 16 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,33 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"friendsofsymfony/http-cache": "^2.15",
"symfony/framework-bundle": "^4.4.0 || ^5.0 || ^6.0",
"symfony/http-foundation": "^4.4.0 || ^5.0 || ^6.0",
"symfony/http-kernel": "^4.4.0 || ^5.0 || ^6.0"
"php": "^8.1",
"friendsofsymfony/http-cache": "^2.15 || 3.x-dev",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0"
},
"require-dev": {
"php-http/guzzle7-adapter": "^0.1.1",
"php-http/message": "^1.0 || ^2.0",
"php-http/httplug": "^2.2.0",
"php-http/discovery": "^1.13",
"guzzlehttp/guzzle": "^7.2",
"mockery/mockery": "^1.3.2",
"mockery/mockery": "^1.6.9",
"monolog/monolog": "*",
"sensio/framework-extra-bundle": "^4.0 || ^5.5.1 || ^6.0",
"doctrine/annotations": "^1.11",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we don't need this anymore

"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0",
"symfony/finder": "^4.4 || ^5.0 || ^6.0",
"symfony/browser-kit": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/finder": "^6.4 || ^7.0",
"phpunit/phpunit": "^9.6.15",
"symfony/security-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
"twig/twig": "^2.13",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0",
"symfony/css-selector": "^4.4 || ^5.0 || ^6.0",
"symfony/expression-language": "^4.4 || ^5.0 || ^6.0",
"symfony/security-bundle": "^6.4 || ^7.0",
"symfony/twig-bundle": "^6.4 || ^7.0",
"twig/twig": "^v3.8",
"symfony/yaml": "^6.4 || ^7.0",
"symfony/css-selector": "^6.4 || ^7.0",
"symfony/expression-language": "^6.4 || ^7.0",
"symfony/monolog-bundle": "^3.0",
"symfony/routing": "^4.4 || ^5.0 || ^6.0",
"symfony/routing": "^6.4 || ^7.0",
"matthiasnoback/symfony-config-test": "^4.3.0 || ^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0"
},
Expand Down
3 changes: 0 additions & 3 deletions src/Command/BaseInvalidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use FOS\HttpCacheBundle\CacheManager;
use LogicException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -24,8 +23,6 @@
*/
abstract class BaseInvalidateCommand extends Command
{
use ContainerAwareTrait;

/**
* @var CacheManager
*/
Expand Down
28 changes: 8 additions & 20 deletions src/Configuration/InvalidatePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@

namespace FOS\HttpCacheBundle\Configuration;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;

/**
* @Annotation
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class InvalidatePath extends ConfigurationAnnotation
class InvalidatePath
{
/**
* @var array
Expand All @@ -34,7 +32,13 @@ public function __construct(
$values = $data;
}

parent::__construct($values);
foreach ($values as $k => $v) {
if (!method_exists($this, $name = 'set'.$k)) {
throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, static::class));
}

$this->$name($v);
}
}

/**
Expand Down Expand Up @@ -62,20 +66,4 @@ public function getPaths()
{
return $this->paths;
}

/**
* {@inheritdoc}
*/
public function getAliasName(): string
{
return 'invalidate_path';
}

/**
* {@inheritdoc}
*/
public function allowArray(): bool
{
return true;
}
}
27 changes: 8 additions & 19 deletions src/Configuration/InvalidateRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

namespace FOS\HttpCacheBundle\Configuration;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

/**
* @Annotation
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class InvalidateRoute extends ConfigurationAnnotation
class InvalidateRoute
{
/**
* @var string
Expand All @@ -44,7 +43,13 @@ public function __construct(

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

parent::__construct($values);
foreach ($values as $k => $v) {
if (!method_exists($this, $name = 'set'.$k)) {
throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, static::class));
}

$this->$name($v);
}
}

/**
Expand Down Expand Up @@ -111,20 +116,4 @@ public function getParams()
{
return $this->params;
}

/**
* {@inheritdoc}
*/
public function getAliasName(): string
{
return 'invalidate_route';
}

/**
* {@inheritdoc}
*/
public function allowArray(): bool
{
return true;
}
}
Loading