Skip to content

Commit

Permalink
Remove annotations support for full compatibility with symfony/framew…
Browse files Browse the repository at this point in the history
…ork-bundle ^7.0 (#40)

This PR is a breaking change that drops annotation support. This makes
it possible to get rid of the `annotation_reader` Symfony DIC service
dependency, truly clearing the path for Symfony 7.
  • Loading branch information
mpdude authored Mar 28, 2024
1 parent 2edab6f commit d199870
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 85 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:
pull_request:

env:
PHP_VERSION: 7.4
PHP_VERSION: 8.1

jobs:
composer-require-checker:
name: Check missing composer requirements
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Konfiguriere PHP-Version und -Einstellungen im Worker-Node
Expand All @@ -35,4 +35,4 @@ jobs:
composer require webfactory/http-cache-bundle
composer show
- name: ComposerRequireChecker
uses: docker://webfactory/composer-require-checker:3.2.0
uses: docker://ghcr.io/webfactory/composer-require-checker:4.8.0
11 changes: 5 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ env:

jobs:
PHPUnit:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include:
- { php-version: 7.2, symfony-locked-version: none, dependency-version: prefer-lowest }
- { php-version: 7.4, symfony-locked-version: 4.4.*, dependency-version: prefer-stable }
- { php-version: 7.4, symfony-locked-version: none, dependency-version: prefer-stable }
- { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-stable }
- { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-lowest }
- { php-version: 8.2, symfony-locked-version: 6.4.*, dependency-version: prefer-stable }
- { php-version: 8.3, symfony-locked-version: none, dependency-version: prefer-stable }
name: PHPUnit (PHP ${{matrix.php-version}}, Symfony Version Lock ${{ matrix.symfony-locked-version }}, ${{ matrix.dependency-version }})
steps:
- uses: shivammathur/setup-php@v2
Expand All @@ -39,6 +38,6 @@ jobs:
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-locked-version }}-${{ matrix.dependency-version }}-
- run: |
composer install --no-interaction --no-progress --ansi --no-scripts
composer update --${{ matrix.dependency-version }} --no-interaction --no-scripts --no-progress --ansi
composer show
- run: vendor/bin/phpunit
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## Version 4.0.0

* Annotation classes from the `\Webfactory\Bundle\WfdMetaBundle\Caching\Annotation` namespace have been removed, annotation support has been removed.
Use attributes for configuration.

## Version 3.4.0

* Using annotations to configure caching is deprecated. A new `\Webfactory\Bundle\WfdMetaBundle\Caching\Attribute\Send304IfNotModified` attribute
is provided to replace annotations-based configuration. Using this bundle for caching configuration remains a deprecated feature by itself.

## Version 3.3.0

* Deprecate Send304IfNotModified annotation. Use WebfactoryHttpCachingBundle and its LastModifiedDeterminators instead. If in a hurry, @see \Webfactory\Bundle\WfdMetaBundle\Caching\WfdMetaQueries for a quick conversion.
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
],

"require": {
"php": ">= 7.2, < 8.4",
"doctrine/annotations": "^1.12",
"php": ">= 8.1",
"doctrine/dbal": "^2.12|^3.0",
"doctrine/orm": "^2.0",
"doctrine/persistence": "^1.3|^2.1",
Expand All @@ -39,8 +38,8 @@
},

"require-dev": {
"phpunit/phpunit": "^8.5",
"symfony/phpunit-bridge": ">=5.0"
"phpunit/phpunit": "^9.6.18",
"symfony/phpunit-bridge": ">=7.0"
},

"autoload": {
Expand Down
23 changes: 0 additions & 23 deletions src/Caching/Annotation/Send304IfNotModified.php

This file was deleted.

23 changes: 0 additions & 23 deletions src/Caching/Annotation/ValidUntilLastTouched.php

This file was deleted.

30 changes: 5 additions & 25 deletions src/Caching/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@

namespace Webfactory\Bundle\WfdMetaBundle\Caching;

use Doctrine\Common\Annotations\Reader;
use ReflectionObject;
use SplObjectStorage;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Webfactory\Bundle\WfdMetaBundle\Caching\Annotation\Send304IfNotModified;
use Webfactory\Bundle\WfdMetaBundle\Caching\Attribute\Send304IfNotModified;
use Webfactory\Bundle\WfdMetaBundle\MetaQueryFactory;

/**
* @deprecated Use WebfactoryHttpCachingBundle instead.
*/
class EventListener
{
protected $reader;

/** @var MetaQueryFactory */
protected $metaQueryFactory;

Expand All @@ -32,9 +29,8 @@ class EventListener
/** @var SplObjectStorage */
protected $lastTouchedResults;

public function __construct(Reader $reader, MetaQueryFactory $metaQueryFactory, $debug)
public function __construct(MetaQueryFactory $metaQueryFactory, $debug)
{
$this->reader = $reader;
$this->metaQueryFactory = $metaQueryFactory;
$this->debug = $debug;
$this->lastTouchedResults = new SplObjectStorage();
Expand Down Expand Up @@ -93,10 +89,8 @@ public function onKernelResponse(ResponseEvent $event)

/**
* @param $callback array A PHP callback (array) pointing to the method to reflect on.
*
* @return Send304IfNotModified|null The attribute, if found. Null otherwise.
*/
protected function findAttribute($callback): ?Attribute\Send304IfNotModified
protected function findAttribute($callback): ?Send304IfNotModified
{
if (!\is_array($callback)) {
return null;
Expand All @@ -105,22 +99,8 @@ protected function findAttribute($callback): ?Attribute\Send304IfNotModified
$object = new ReflectionObject($callback[0]);
$method = $object->getMethod($callback[1]);

if (\PHP_MAJOR_VERSION >= 8) {
$attributes = $method->getAttributes(\Webfactory\Bundle\WfdMetaBundle\Caching\Attribute\Send304IfNotModified::class);

if ($attributes) {
return $attributes[0]->newInstance();
}
}

foreach ($this->reader->getMethodAnnotations($method) as $configuration) {
if ($configuration instanceof Send304IfNotModified) {
@trigger_error(sprintf('Using annotations to configure wfd_meta based caching on %s::%s is deprecated, use attribute-based configuration instead.', $method->class, $method->name), \E_USER_DEPRECATED);

return $configuration;
}
}
$attributes = $method->getAttributes(Send304IfNotModified::class);

return null;
return $attributes ? $attributes[0]->newInstance() : null;
}
}
1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</service>

<service id="Webfactory\Bundle\WfdMetaBundle\Caching\EventListener">
<argument type="service" id="annotation_reader" />
<argument type="service" id="Webfactory\Bundle\WfdMetaBundle\MetaQueryFactory" />
<argument>%kernel.debug%</argument>

Expand Down

0 comments on commit d199870

Please sign in to comment.