Skip to content

Commit 9a17f71

Browse files
authored
Merge pull request #2352 from mbabker/inline-compat-controller
Inline compat controller layer
2 parents 8ef78c2 + 31a2fea commit 9a17f71

File tree

3 files changed

+38
-71
lines changed

3 files changed

+38
-71
lines changed

Controller/AbstractFOSRestController.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,47 @@
1414
use FOS\RestBundle\View\ViewHandlerInterface;
1515
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1616

17-
$ref = new \ReflectionMethod(AbstractController::class, 'getSubscribedServices');
18-
1917
// Does the AbstractController::getSubscribedServices() method have a return type hint?
20-
if (null !== $ref->getReturnType()) {
21-
class_alias(PostSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController');
18+
if (null !== (new \ReflectionMethod(AbstractController::class, 'getSubscribedServices'))->getReturnType()) {
19+
/**
20+
* Compat class for Symfony 6.0 and newer support.
21+
*
22+
* @internal
23+
*/
24+
abstract class BaseAbstractFOSRestController extends AbstractController
25+
{
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public static function getSubscribedServices(): array
30+
{
31+
$subscribedServices = parent::getSubscribedServices();
32+
$subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class;
33+
34+
return $subscribedServices;
35+
}
36+
}
2237
} else {
23-
class_alias(PreSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController');
38+
/**
39+
* Compat class for Symfony 5.4 and older support.
40+
*
41+
* @internal
42+
*/
43+
abstract class BaseAbstractFOSRestController extends AbstractController
44+
{
45+
/**
46+
* @return array
47+
*/
48+
public static function getSubscribedServices()
49+
{
50+
$subscribedServices = parent::getSubscribedServices();
51+
$subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class;
52+
53+
return $subscribedServices;
54+
}
55+
}
2456
}
57+
2558
/**
2659
* Controllers using the View functionality of FOSRestBundle.
2760
*/

Controller/PostSymfony6AbstractFOSRestController.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

Controller/PreSymfony6AbstractFOSRestController.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)