Skip to content
Open
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
Changelog
=========

## Version 3.0.0

* Removed Doctrine annotation support. Use PHP 8 attributes instead.
* Removed `doctrine/annotations` dependency.
* PHP 8.0 is now the minimum required version.

## Version 2.4.0
* Add support for PHP 8 attributes

* Added PHP 8 attributes as an alternative to Doctrine annotations (deprecated).

## Version 2.0

Expand Down
9 changes: 3 additions & 6 deletions Controller/PassthruController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

namespace Webfactory\Bundle\LegacyIntegrationBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation as Legacy;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute as Legacy;

class PassthruController
{
/**
* @Legacy\Dispatch
* @Legacy\Passthru
*/
#[Legacy\Dispatch]
#[Legacy\Passthru]
public function indexAction()
{
}
Expand Down
33 changes: 9 additions & 24 deletions EventListener/LegacyApplicationDispatchingEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

namespace Webfactory\Bundle\LegacyIntegrationBundle\EventListener;

use Doctrine\Common\Annotations\Reader;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Dispatch;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\Dispatch as DispatchAttribute;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Attribute\Dispatch;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\LegacyApplication;

Expand All @@ -22,19 +20,16 @@ class LegacyApplicationDispatchingEventListener
*/
private $legacyApplication;

protected $reader;

protected $stopwatch;

/**
* @var Filter[]
*/
protected $filters = [];

public function __construct(LegacyApplication $legacyApplication, Reader $reader)
public function __construct(LegacyApplication $legacyApplication)
{
$this->legacyApplication = $legacyApplication;
$this->reader = $reader;
}

public function addFilter(Filter $filter)
Expand All @@ -51,26 +46,16 @@ public function onKernelController(ControllerEvent $event)
$object = new \ReflectionObject($controller[0]);
$method = $object->getMethod($controller[1]);

$dispatch = false;
foreach ($this->reader->getMethodAnnotations($method) as $configuration) {
if ($configuration instanceof Dispatch) {
$dispatch = true;
break;
}
}

if (!$dispatch && $method->getAttributes(DispatchAttribute::class)) {
$dispatch = true;
if (!$method->getAttributes(Dispatch::class)) {
return;
}

if ($dispatch) {
$response = $this->legacyApplication->handle($event->getRequest(), $event->getRequestType(), false);
$response = $this->legacyApplication->handle($event->getRequest(), $event->getRequestType(), false);

foreach ($this->filters as $filter) {
$filter->filter($event, $response);
if ($event->isPropagationStopped()) {
break;
}
foreach ($this->filters as $filter) {
$filter->filter($event, $response);
if ($event->isPropagationStopped()) {
break;
}
}
}
Expand Down
29 changes: 0 additions & 29 deletions Integration/Annotation/Dispatch.php

This file was deleted.

31 changes: 0 additions & 31 deletions Integration/Annotation/Filter.php

This file was deleted.

31 changes: 0 additions & 31 deletions Integration/Annotation/IgnoreHeader.php

This file was deleted.

29 changes: 0 additions & 29 deletions Integration/Annotation/IgnoreRedirect.php

This file was deleted.

29 changes: 0 additions & 29 deletions Integration/Annotation/KeepCookies.php

This file was deleted.

29 changes: 0 additions & 29 deletions Integration/Annotation/KeepHeaders.php

This file was deleted.

29 changes: 0 additions & 29 deletions Integration/Annotation/Passthru.php

This file was deleted.

8 changes: 4 additions & 4 deletions Integration/Attribute/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ public function __construct(?string $class = null, ?string $service = null)
$this->service = $service;

if (!$this->class && !$this->service) {
throw new \Exception('Parameter "class" or "service" is missing in Webfactory\Bundle\LegacyIntegrationBundle\Integration\Annotation\Filter.');
throw new \Exception('Parameter "class" or "service" is missing in '.self::class.'.');
}
}

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.');
throw new \Exception('Unknown class '.$class.' configured with the '.self::class.' attribute.');
}
$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.');
throw new \Exception('Unknown service '.$service.' configured with the '.self::class.' attribute.');
}
$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.');
throw new \Exception('Class '.\get_class($filter).' configured with the '.self::class.' attribute is not a '.FilterInterface::class.'.');
}

return $filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@

namespace Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter;

use Doctrine\Common\Annotations\Reader;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Webfactory\Bundle\LegacyIntegrationBundle\Integration\Filter as FilterInterface;

class ControllerAnnotations implements FilterInterface
class ControllerAttributes implements FilterInterface
{
protected $reader;
protected $container;

public function __construct(Reader $reader, ContainerInterface $container)
public function __construct(ContainerInterface $container)
{
$this->reader = $reader;
$this->container = $container;
}

Expand All @@ -34,15 +31,6 @@ public function filter(ControllerEvent $event, Response $response)
$object = new \ReflectionObject($controller[0]);
$method = $object->getMethod($controller[1]);

foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
if ($annotation instanceof Factory) {
$annotation->createFilter($this->container)->filter($event, $response);
if ($event->isPropagationStopped()) {
return;
}
}
}

foreach ($method->getAttributes(Factory::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
$attribute->newInstance()->createFilter($this->container)->filter($event, $response);
if ($event->isPropagationStopped()) {
Expand Down
Loading