Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Symfony 6 support #2340

Merged
merged 13 commits into from
Nov 22, 2021
24 changes: 10 additions & 14 deletions Controller/AbstractFOSRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
namespace FOS\RestBundle\Controller;

use FOS\RestBundle\View\ViewHandlerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Contracts\Service\ServiceSubscriberInterface;

$ref = new \ReflectionMethod(ServiceSubscriberInterface::class, 'getSubscribedServices');

// Has the ServiceSubscriberInterface a return type hint
if ($ref->getReturnType() !== null) {
goetas marked this conversation as resolved.
Show resolved Hide resolved
class_alias(PostSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController');
} else {
class_alias(PreSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController');
}
/**
* Controllers using the View functionality of FOSRestBundle.
*/
abstract class AbstractFOSRestController extends AbstractController
abstract class AbstractFOSRestController extends BaseAbstractFOSRestController
{
use ControllerTrait;

/**
* @return ViewHandlerInterface
*/
Expand All @@ -32,15 +39,4 @@ protected function getViewHandler()

return $this->viewhandler;
}

/**
* {@inheritdoc}
*/
public static function getSubscribedServices(): array
{
$subscribedServices = parent::getSubscribedServices();
$subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class;

return $subscribedServices;
}
}
32 changes: 32 additions & 0 deletions Controller/PostSymfony6AbstractFOSRestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* 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;
}
}
34 changes: 34 additions & 0 deletions Controller/PreSymfony6AbstractFOSRestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* 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;

/**
* {@inheritdoc}
mbabker marked this conversation as resolved.
Show resolved Hide resolved
*/
public static function getSubscribedServices()
{
$subscribedServices = parent::getSubscribedServices();
$subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class;

return $subscribedServices;
}
}