Skip to content
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

Remove annotations support to gain Symfony 7 compatibility #11

Merged
merged 18 commits into from
Mar 28, 2024
Merged
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
29 changes: 15 additions & 14 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
name: Dependencies

permissions:
contents: read

on:
push:
branches:
- master
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: shivammathur/setup-php@v2
- uses: actions/checkout@v3
- name: Konfiguriere PHP-Version und -Einstellungen im Worker-Node
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
coverage: none
tools: composer:v2
- uses: actions/checkout@v3
- uses: actions/cache@v3
ini-values: variables_order=EGPCS, date.timezone=Europe/Berlin
- name: Cache Composer Dependencies
uses: actions/cache@v1
with:
path: vendor
key: composer-${{ runner.os }}-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }}
path: vendor/
key: composer-${{ env.PHP_VERSION }}-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-${{ env.PHP_VERSION }}-
composer-${{ runner.os }}-
composer-${{ env.PHP_VERSION }}-${{ github.ref }}
composer-${{ env.PHP_VERSION }}-
- run: |
composer install --no-interaction --no-progress --ansi --no-scripts
composer install --no-interaction --no-scripts --no-progress --no-suggest
composer show
- uses: docker://webfactory/composer-require-checker:3.2.0
- name: ComposerRequireChecker
uses: docker://ghcr.io/webfactory/composer-require-checker:4.8.0
2 changes: 1 addition & 1 deletion .github/workflows/fix-cs-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: Coding Standards
jobs:
open-pr-for-cs-violations:
name: PHP-CS-Fixer
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lock-symfony-version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

cat <<< $(jq --arg version $VERSION '.require |= with_entries(if ((.key|test("^symfony/"))) then .value=$version else . end)' < composer.json) > composer.json
cat <<< $(jq --arg version $VERSION '.require |= with_entries(if ((.key|test("^symfony/deprecation-contracts")|not) and (.key|test("^symfony/"))) then .value=$version else . end)' < composer.json) > composer.json
9 changes: 4 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,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: none, dependency-version: prefer-lowest }
- { 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: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ services:
- @repository_post
`

and note the service name to the Annotation:
and put the service name into the attribute:

#[ReplaceWithNotModifiedResponse(["@app_caching_latest_posts"])]

To combine multiple LastModifiedDeterminators, simply add all of them to the annotation:
To combine multiple LastModifiedDeterminators, simply add all of them to the attribute:

#[ReplaceWithNotModifiedResponse([
"@app_caching_latest_posts",
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade notes for `WebfactoryHttpCacheBundle`

## Version 2.0.0

* Annotations support and the `\Webfactory\HttpCacheBundle\NotModified\Annotation\ReplaceWithNotModifiedResponse` class have been removed.

## Version 1.4.0

* The `\Webfactory\HttpCacheBundle\NotModified\Annotation\ReplaceWithNotModifiedResponse` annotation has been deprecated. Use the
Expand Down
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
],

"require": {
"php": "^7.1|8.0.*|8.1.*",
"doctrine/annotations": "^1.0",
"symfony/config": "^4.4 | ^5.0 | ^6.0",
"symfony/dependency-injection": "^4.4 | ^5.0 | ^6.0",
"php": "^8.1",
"symfony/config": "^5.0 | ^6.0 | ^7.0",
"symfony/dependency-injection": "^5.0 | ^6.0 | ^7.0",
"symfony/deprecation-contracts": "^2.0|^3.0",
"symfony/http-foundation": "^4.4 | ^5.0 | ^6.0",
"symfony/http-kernel": "^4.4 | ^5.0 | ^6.0"
"symfony/http-foundation": "^5.0 | ^6.0 | ^7.0",
"symfony/http-kernel": "^5.3 | ^6.0 | ^7.0"
},

"require-dev": {
"phpunit/phpunit": "^8.5|^9.0",
"symfony/phpunit-bridge": "^5.0 | ^6.0"
"phpunit/phpunit": "^9.6",
"symfony/phpunit-bridge": "^6.0 | ^7.0"
},

"suggest": {
Expand Down
9 changes: 3 additions & 6 deletions src/DependencyInjection/WebfactoryHttpCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* Symfony Bundle Extension class.
*/
class WebfactoryHttpCacheExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$locator = new FileLocator(__DIR__.'/../NotModified');
$yamlLoader = new XmlFileLoader($container, $locator);
$yamlLoader->load('services.xml');
$loader = new XmlFileLoader($container, $locator);
$loader->load('services.xml');
}
}
33 changes: 0 additions & 33 deletions src/NotModified/Annotation/ReplaceWithNotModifiedResponse.php

This file was deleted.

4 changes: 1 addition & 3 deletions src/NotModified/Attribute/ReplaceWithNotModifiedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
* This attribute determines the latest last modified date over all of its LastModifiedDeterminators. This date is used
* by the \Webfactory\HttpCacheBundle\NotModified\EventListener to possibly replace the execution of a controller with
* sending a Not Modified HTTP response.
*
* @final
*/
#[Attribute(Attribute::TARGET_METHOD)]
class ReplaceWithNotModifiedResponse
final class ReplaceWithNotModifiedResponse
{
/** @var array */
private $parameters;
Expand Down
32 changes: 5 additions & 27 deletions src/NotModified/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

namespace Webfactory\HttpCacheBundle\NotModified;

use Doctrine\Common\Annotations\Reader;
use ReflectionMethod;
use SplObjectStorage;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Webfactory\HttpCacheBundle\NotModified;
use Webfactory\HttpCacheBundle\NotModified\Attribute\ReplaceWithNotModifiedResponse;

/**
* Symfony EventListener for adding a "last modified" header to the response on the one hand. On the other hand, it
Expand All @@ -25,9 +24,6 @@
*/
final class EventListener
{
/** @var Reader */
private $reader;

/** @var ContainerInterface */
private $container;

Expand All @@ -44,9 +40,8 @@ final class EventListener
*/
private $debug;

public function __construct(Reader $reader, ContainerInterface $container, bool $debug = false)
public function __construct(ContainerInterface $container, bool $debug = false)
{
$this->reader = $reader;
$this->container = $container;
$this->lastModified = new SplObjectStorage();
$this->debug = $debug;
Expand Down Expand Up @@ -107,7 +102,7 @@ public function onKernelResponse(ResponseEvent $event)
/**
* @param $controllerCallable callable PHP callback pointing to the method to reflect on.
*
* @return ReplaceWithNotModifiedResponse|null The annotation, if found. Null otherwise.
* @return ?ReplaceWithNotModifiedResponse The annotation, if found. Null otherwise.
*/
private function findAnnotation(callable $controllerCallable)
{
Expand All @@ -118,25 +113,8 @@ private function findAnnotation(callable $controllerCallable)
[$class, $methodName] = $controllerCallable;
$method = new ReflectionMethod($class, $methodName);

if (PHP_MAJOR_VERSION >= 8) {
$attributes = $method->getAttributes(NotModified\Attribute\ReplaceWithNotModifiedResponse::class);

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

/** @var ReplaceWithNotModifiedResponse|null $annotation */
$annotation = $this->reader->getMethodAnnotation($method, NotModified\Annotation\ReplaceWithNotModifiedResponse::class);

if ($annotation) {
trigger_deprecation(
'webfactory/http-cache-bundle',
'1.4.0',
'Configuring webfactory/http-cache-bundle with annotations is deprecated, use attributes instead.'
);
}
$attributes = $method->getAttributes(ReplaceWithNotModifiedResponse::class);

return $annotation;
return $attributes ? $attributes[0]->newInstance() : null;
}
}
1 change: 0 additions & 1 deletion src/NotModified/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="Webfactory\HttpCacheBundle\NotModified\EventListener" class="Webfactory\HttpCacheBundle\NotModified\EventListener" public="true">
<argument type="service" id="annotation_reader" />
<argument type="service" id="service_container" />
<argument>%kernel.debug%</argument>
<tag name="kernel.event_listener" event="kernel.controller" priority="-200" />
Expand Down
3 changes: 0 additions & 3 deletions src/WebfactoryHttpCacheBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Symfony Bundle class.
*/
class WebfactoryHttpCacheBundle extends Bundle
{
}
Loading
Loading