Skip to content

Commit

Permalink
Merge pull request #2352 from mbabker/inline-compat-controller
Browse files Browse the repository at this point in the history
Inline compat controller layer
  • Loading branch information
goetas authored Dec 1, 2021
2 parents 8ef78c2 + 31a2fea commit 9a17f71
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 71 deletions.
43 changes: 38 additions & 5 deletions Controller/AbstractFOSRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
32 changes: 0 additions & 32 deletions Controller/PostSymfony6AbstractFOSRestController.php

This file was deleted.

34 changes: 0 additions & 34 deletions Controller/PreSymfony6AbstractFOSRestController.php

This file was deleted.

0 comments on commit 9a17f71

Please sign in to comment.