From c8220da2683c713b51eb217a497e8817df9eafec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20G=C3=BCthler?= Date: Wed, 18 Mar 2026 17:00:48 +0100 Subject: [PATCH] Add PHP attributes and deprecate annotations --- Integration/Annotation/Dispatch.php | 15 +++++- Integration/Annotation/Filter.php | 47 +++++------------- Integration/Annotation/IgnoreHeader.php | 25 +++++----- Integration/Annotation/IgnoreRedirect.php | 17 ++++--- Integration/Annotation/KeepCookies.php | 17 +++++-- Integration/Annotation/KeepHeaders.php | 17 +++++-- Integration/Annotation/Passthru.php | 17 ++++--- Integration/Attribute/Dispatch.php | 16 ++++++ Integration/Attribute/Filter.php | 59 +++++++++++++++++++++++ Integration/Attribute/IgnoreHeader.php | 33 +++++++++++++ Integration/Attribute/IgnoreRedirect.php | 23 +++++++++ Integration/Attribute/KeepCookies.php | 22 +++++++++ Integration/Attribute/KeepHeaders.php | 22 +++++++++ Integration/Attribute/Passthru.php | 23 +++++++++ 14 files changed, 280 insertions(+), 73 deletions(-) create mode 100644 Integration/Attribute/Dispatch.php create mode 100644 Integration/Attribute/Filter.php create mode 100644 Integration/Attribute/IgnoreHeader.php create mode 100644 Integration/Attribute/IgnoreRedirect.php create mode 100644 Integration/Attribute/KeepCookies.php create mode 100644 Integration/Attribute/KeepHeaders.php create mode 100644 Integration/Attribute/Passthru.php diff --git a/Integration/Annotation/Dispatch.php b/Integration/Annotation/Dispatch.php index 5ead49f..bbe841a 100644 --- a/Integration/Annotation/Dispatch.php +++ b/Integration/Annotation/Dispatch.php @@ -8,9 +8,22 @@ namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\Dispatch as DispatchAttribute; + /** * @Annotation + * @deprecated Use the attribute instead. */ -class Dispatch +class Dispatch extends DispatchAttribute { + public function __construct() + { + trigger_deprecation( + 'webfactory/legacy-integration-bundle', + '2.4.0', + 'The %s annotation has been deprecated, use the %s attribute instead.', + __CLASS__, + DispatchAttribute::class + ); + } } diff --git a/Integration/Annotation/Filter.php b/Integration/Annotation/Filter.php index ab05b2d..f6d8efa 100644 --- a/Integration/Annotation/Filter.php +++ b/Integration/Annotation/Filter.php @@ -8,49 +8,24 @@ namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter as FilterInterface; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\Filter as FilterAttribute; /** * @Annotation + * @deprecated Use the attribute instead. */ -class Filter implements Factory +class Filter extends FilterAttribute { - protected $class; - protected $service; - public function __construct($values) { - if (isset($values['class'])) { - $this->class = $values['class']; - } - if (isset($values['service'])) { - $this->service = $values['service']; - } - if (!$this->class && !$this->service) { - throw new \Exception('Parameter "class" or "service" is missing in Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter.'); - } - } - - public function createFilter(ContainerInterface $container) - { - if ($class = $this->class) { - if (!class_exists($class)) { - throw new \Exception('Unknown class '.$class.' configured with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter annotation.'); - } - $filter = new $class(); - } - if ($service = $this->service) { - if (!$container->has($service)) { - throw new \Exception('Unknown service '.$service.' configured with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter annotation.'); - } - $filter = $container->get($service); - } - if (!$filter instanceof FilterInterface) { - throw new \Exception('Class '.\get_class($filter).' configured with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter annotation is not a Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter.'); - } + trigger_deprecation( + 'webfactory/legacy-integration-bundle', + '2.4.0', + 'The %s annotation has been deprecated, use the %s attribute instead.', + __CLASS__, + FilterAttribute::class + ); - return $filter; + parent::__construct($values); } } diff --git a/Integration/Annotation/IgnoreHeader.php b/Integration/Annotation/IgnoreHeader.php index 1581daa..bcbdde5 100644 --- a/Integration/Annotation/IgnoreHeader.php +++ b/Integration/Annotation/IgnoreHeader.php @@ -8,27 +8,24 @@ namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\IgnoreHeader as IgnoreHeaderFilter; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\IgnoreHeader as IgnoreHeaderAttribute; /** * @Annotation + * @deprecated Use the attribute instead. */ -class IgnoreHeader implements Factory +class IgnoreHeader extends IgnoreHeaderAttribute { - protected $header; - public function __construct(array $values) { - $this->header = array_shift($values); - if (!\is_string($this->header)) { - throw new \Exception("Please define a header with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\IgnoreHeader annotation."); - } - } + trigger_deprecation( + 'webfactory/legacy-integration-bundle', + '2.4.0', + 'The %s annotation has been deprecated, use the %s attribute instead.', + __CLASS__, + IgnoreHeaderAttribute::class + ); - public function createFilter(ContainerInterface $container) - { - return new IgnoreHeaderFilter($this->header); + parent::__construct($values); } } diff --git a/Integration/Annotation/IgnoreRedirect.php b/Integration/Annotation/IgnoreRedirect.php index 0da3b1f..5e8ad0e 100644 --- a/Integration/Annotation/IgnoreRedirect.php +++ b/Integration/Annotation/IgnoreRedirect.php @@ -8,17 +8,22 @@ namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\IgnoreRedirect as IgnoreRedirectFilter; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\IgnoreRedirect as IgnoreRedirectAttribute; /** * @Annotation + * @deprecated Use the attribute instead. */ -class IgnoreRedirect implements Factory +class IgnoreRedirect extends IgnoreRedirectAttribute { - public function createFilter(ContainerInterface $container) + public function __construct() { - return new IgnoreRedirectFilter(); + trigger_deprecation( + 'webfactory/legacy-integration-bundle', + '2.4.0', + 'The %s annotation has been deprecated, use the %s attribute instead.', + __CLASS__, + IgnoreRedirectAttribute::class + ); } } diff --git a/Integration/Annotation/KeepCookies.php b/Integration/Annotation/KeepCookies.php index 60859f5..e0c83a3 100644 --- a/Integration/Annotation/KeepCookies.php +++ b/Integration/Annotation/KeepCookies.php @@ -8,15 +8,22 @@ namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\KeepCookies as KeepCookiesAttribute; + /** * @Annotation + * @deprecated Use the attribute instead. */ -class KeepCookies +class KeepCookies extends KeepCookiesAttribute { - public $value; - - public function shouldKeep($name) + public function __construct() { - return null === $this->value || \in_array($name, $this->value); + trigger_deprecation( + 'webfactory/legacy-integration-bundle', + '2.4.0', + 'The %s annotation has been deprecated, use the %s attribute instead.', + __CLASS__, + KeepCookiesAttribute::class + ); } } diff --git a/Integration/Annotation/KeepHeaders.php b/Integration/Annotation/KeepHeaders.php index 83679a5..af17c6c 100644 --- a/Integration/Annotation/KeepHeaders.php +++ b/Integration/Annotation/KeepHeaders.php @@ -8,15 +8,22 @@ namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\KeepHeaders as KeepHeadersAttribute; + /** * @Annotation + * @deprecated Use the attribute instead. */ -class KeepHeaders +class KeepHeaders extends KeepHeadersAttribute { - public $value; - - public function shouldKeep($name) + public function __construct() { - return null === $this->value || \in_array($name, $this->value); + trigger_deprecation( + 'webfactory/legacy-integration-bundle', + '2.4.0', + 'The %s annotation has been deprecated, use the %s attribute instead.', + __CLASS__, + KeepHeadersAttribute::class + ); } } diff --git a/Integration/Annotation/Passthru.php b/Integration/Annotation/Passthru.php index d8f9bc1..ca53dc5 100644 --- a/Integration/Annotation/Passthru.php +++ b/Integration/Annotation/Passthru.php @@ -8,17 +8,22 @@ namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; -use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\PassthruLegacyResponseFilter; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\Passthru as PassthruAttribute; /** * @Annotation + * @deprecated Use the attribute instead. */ -class Passthru implements Factory +class Passthru extends PassthruAttribute { - public function createFilter(ContainerInterface $container) + public function __construct() { - return new PassthruLegacyResponseFilter(); + trigger_deprecation( + 'webfactory/legacy-integration-bundle', + '2.4.0', + 'The %s annotation has been deprecated, use the %s attribute instead.', + __CLASS__, + PassthruAttribute::class + ); } } diff --git a/Integration/Attribute/Dispatch.php b/Integration/Attribute/Dispatch.php new file mode 100644 index 0000000..cd3d904 --- /dev/null +++ b/Integration/Attribute/Dispatch.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute; + +use Attribute; + +#[Attribute(Attribute::TARGET_METHOD)] +class Dispatch +{ +} diff --git a/Integration/Attribute/Filter.php b/Integration/Attribute/Filter.php new file mode 100644 index 0000000..28399d5 --- /dev/null +++ b/Integration/Attribute/Filter.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute; + +use Attribute; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter as FilterInterface; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; + +#[Attribute(Attribute::TARGET_METHOD)] +class Filter implements Factory +{ + protected $class; + protected $service; + + public function __construct($values) + { + if (isset($values['class'])) { + $this->class = $values['class']; + } + + if (isset($values['service'])) { + $this->service = $values['service']; + } + + if (!$this->class && !$this->service) { + throw new \Exception('Parameter "class" or "service" is missing in Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter.'); + } + } + + public function createFilter(ContainerInterface $container) + { + if ($class = $this->class) { + if (!class_exists($class)) { + throw new \Exception('Unknown class '.$class.' configured with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter annotation.'); + } + $filter = new $class(); + } + + if ($service = $this->service) { + if (!$container->has($service)) { + throw new \Exception('Unknown service '.$service.' configured with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter annotation.'); + } + $filter = $container->get($service); + } + + if (!$filter instanceof FilterInterface) { + throw new \Exception('Class '.\get_class($filter).' configured with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter annotation is not a Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter.'); + } + + return $filter; + } +} diff --git a/Integration/Attribute/IgnoreHeader.php b/Integration/Attribute/IgnoreHeader.php new file mode 100644 index 0000000..6a64a70 --- /dev/null +++ b/Integration/Attribute/IgnoreHeader.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute; + +use Attribute; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\IgnoreHeader as IgnoreHeaderFilter; + +#[Attribute(Attribute::TARGET_METHOD)] +class IgnoreHeader implements Factory +{ + protected $header; + + public function __construct(array $values) + { + $this->header = array_shift($values); + if (!\is_string($this->header)) { + throw new \Exception("Please define a header with the Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\IgnoreHeader annotation."); + } + } + + public function createFilter(ContainerInterface $container) + { + return new IgnoreHeaderFilter($this->header); + } +} diff --git a/Integration/Attribute/IgnoreRedirect.php b/Integration/Attribute/IgnoreRedirect.php new file mode 100644 index 0000000..9596099 --- /dev/null +++ b/Integration/Attribute/IgnoreRedirect.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute; + +use Attribute; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\IgnoreRedirect as IgnoreRedirectFilter; + +#[Attribute(Attribute::TARGET_METHOD)] +class IgnoreRedirect implements Factory +{ + public function createFilter(ContainerInterface $container) + { + return new IgnoreRedirectFilter(); + } +} diff --git a/Integration/Attribute/KeepCookies.php b/Integration/Attribute/KeepCookies.php new file mode 100644 index 0000000..d568486 --- /dev/null +++ b/Integration/Attribute/KeepCookies.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute; + +use Attribute; + +#[Attribute(Attribute::TARGET_METHOD)] +class KeepCookies +{ + public $value; + + public function shouldKeep($name) + { + return null === $this->value || \in_array($name, $this->value); + } +} diff --git a/Integration/Attribute/KeepHeaders.php b/Integration/Attribute/KeepHeaders.php new file mode 100644 index 0000000..752883a --- /dev/null +++ b/Integration/Attribute/KeepHeaders.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute; + +use Attribute; + +#[Attribute(Attribute::TARGET_METHOD)] +class KeepHeaders +{ + public $value; + + public function shouldKeep($name) + { + return null === $this->value || \in_array($name, $this->value); + } +} diff --git a/Integration/Attribute/Passthru.php b/Integration/Attribute/Passthru.php new file mode 100644 index 0000000..453940b --- /dev/null +++ b/Integration/Attribute/Passthru.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute; + +use Attribute; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\Factory; +use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter\PassthruLegacyResponseFilter; + +#[Attribute(Attribute::TARGET_METHOD)] +class Passthru implements Factory +{ + public function createFilter(ContainerInterface $container) + { + return new PassthruLegacyResponseFilter(); + } +}