diff --git a/Controller/AbstractFOSRestController.php b/Controller/AbstractFOSRestController.php index 18e6ebdd7..77aecbe50 100644 --- a/Controller/AbstractFOSRestController.php +++ b/Controller/AbstractFOSRestController.php @@ -14,14 +14,47 @@ use FOS\RestBundle\View\ViewHandlerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -$ref = new \ReflectionMethod(AbstractController::class, 'getSubscribedServices'); - // Does the AbstractController::getSubscribedServices() method have a return type hint? -if (null !== $ref->getReturnType()) { - class_alias(PostSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController'); +if (null !== (new \ReflectionMethod(AbstractController::class, 'getSubscribedServices'))->getReturnType()) { + /** + * Compat class for Symfony 6.0 and newer support. + * + * @internal + */ + abstract class BaseAbstractFOSRestController extends AbstractController + { + /** + * {@inheritdoc} + */ + public static function getSubscribedServices(): array + { + $subscribedServices = parent::getSubscribedServices(); + $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; + + return $subscribedServices; + } + } } else { - class_alias(PreSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController'); + /** + * Compat class for Symfony 5.4 and older support. + * + * @internal + */ + abstract class BaseAbstractFOSRestController extends AbstractController + { + /** + * @return array + */ + public static function getSubscribedServices() + { + $subscribedServices = parent::getSubscribedServices(); + $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; + + return $subscribedServices; + } + } } + /** * Controllers using the View functionality of FOSRestBundle. */ diff --git a/Controller/PostSymfony6AbstractFOSRestController.php b/Controller/PostSymfony6AbstractFOSRestController.php deleted file mode 100644 index 444e6bf51..000000000 --- a/Controller/PostSymfony6AbstractFOSRestController.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\RestBundle\Controller; - -use FOS\RestBundle\View\ViewHandlerInterface; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; - -/** - * @internal - */ -abstract class PostSymfony6AbstractFOSRestController extends AbstractController -{ - /** - * {@inheritdoc} - */ - public static function getSubscribedServices(): array - { - $subscribedServices = parent::getSubscribedServices(); - $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; - - return $subscribedServices; - } -} diff --git a/Controller/PreSymfony6AbstractFOSRestController.php b/Controller/PreSymfony6AbstractFOSRestController.php deleted file mode 100644 index ebf72c293..000000000 --- a/Controller/PreSymfony6AbstractFOSRestController.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\RestBundle\Controller; - -use FOS\RestBundle\View\ViewHandlerInterface; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; - -/** - * @internal - */ -abstract class PreSymfony6AbstractFOSRestController extends AbstractController -{ - use ControllerTrait; - - /** - * @return array - */ - public static function getSubscribedServices() - { - $subscribedServices = parent::getSubscribedServices(); - $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; - - return $subscribedServices; - } -}