diff --git a/Controller/TemplatingExceptionController.php b/Controller/TemplatingExceptionController.php deleted file mode 100644 index 7cbf14484..000000000 --- a/Controller/TemplatingExceptionController.php +++ /dev/null @@ -1,53 +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\Util\ExceptionValueMap; -use FOS\RestBundle\View\ViewHandlerInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Templating\EngineInterface; -use Symfony\Component\Templating\TemplateReferenceInterface; -use Twig\Environment; - -/** - * @deprecated since FOSRestBundle 2.8 - */ -abstract class TemplatingExceptionController extends ExceptionController -{ - protected $templating; - - public function __construct( - ViewHandlerInterface $viewHandler, - ExceptionValueMap $exceptionCodes, - $showException, - $templating - ) { - if (!$templating instanceof EngineInterface && !$templating instanceof Environment) { - throw new \TypeError(sprintf('The fourth argument of %s must be an instance of %s or %s, but %s was given.', __METHOD__, EngineInterface::class, Environment::class, is_object($templating) ? get_class($templating) : gettype($templating))); - } - - parent::__construct($viewHandler, $exceptionCodes, $showException); - - $this->templating = $templating; - } - - /** - * Finds the template for the given format and status code. - * - * @param Request $request - * @param int $statusCode - * @param bool $showException - * - * @return string|TemplateReferenceInterface - */ - abstract protected function findTemplate(Request $request, $statusCode, $showException); -} diff --git a/Controller/TwigExceptionController.php b/Controller/TwigExceptionController.php deleted file mode 100644 index d707baeb8..000000000 --- a/Controller/TwigExceptionController.php +++ /dev/null @@ -1,102 +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 Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Templating\EngineInterface; -use Twig\Environment; -use Twig\Error\LoaderError; -use Twig\Loader\ExistsLoaderInterface; - -/** - * Custom ExceptionController that uses the view layer and supports HTTP response status code mapping. - * It additionally is able to prepare the template parameters for the core EngineInterface. - * - * @deprecated since FOSRestBundle 2.8 - */ -class TwigExceptionController extends TemplatingExceptionController -{ - /** - * {@inheritdoc} - */ - protected function createView(\Exception $exception, $code, array $templateData, Request $request, $showException) - { - $view = parent::createView($exception, $code, $templateData, $request, $showException); - $view->setTemplate($this->findTemplate($request, $code, $showException)); - - return $view; - } - - /** - * {@inheritdoc} - * - * This code is inspired by TwigBundle and should be synchronized on a regular basis - * see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php - */ - protected function findTemplate(Request $request, $statusCode, $showException) - { - $format = $request->getRequestFormat(); - - $name = $showException ? 'exception' : 'error'; - if ($showException && 'html' == $format) { - $name = 'exception_full'; - } - - // For error pages, try to find a template for the specific HTTP status code and format - if (!$showException) { - $template = sprintf('@Twig/Exception/%s%s.%s.twig', $name, $statusCode, $format); - if ( - ($this->templating instanceof EngineInterface && $this->templating->exists($template)) || - ($this->templating instanceof Environment && $this->templateExists($template)) - ) { - return $template; - } - } - - // try to find a template for the given format - $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format); - if ( - ($this->templating instanceof EngineInterface && $this->templating->exists($template)) || - ($this->templating instanceof Environment && $this->templateExists($template)) - ) { - return $template; - } - - // default to a generic HTML exception - $request->setRequestFormat('html'); - - return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name); - } - - /** - * See if a template exists using the modern Twig mechanism. - * - * This code is based on TwigBundle and should be removed when the minimum required - * version of Twig is >= 3.0. See src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php - */ - private function templateExists(string $template): bool - { - $loader = $this->templating->getLoader(); - if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) { - return $loader->exists($template); - } - - try { - $loader->getSourceContext($template)->getCode(); - - return true; - } catch (LoaderError $e) { - } - - return false; - } -} diff --git a/DependencyInjection/Compiler/TwigExceptionPass.php b/DependencyInjection/Compiler/TwigExceptionPass.php deleted file mode 100644 index 7d1880283..000000000 --- a/DependencyInjection/Compiler/TwigExceptionPass.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\RestBundle\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; - -/** - * Remove the 'fos_rest.exception.twig_controller' service if templating is not enabled and configure default exception controller. - * - * @internal - */ -final class TwigExceptionPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container) - { - // when no custom exception controller has been set - if ($container->hasDefinition('fos_rest.exception_listener') && - null === $container->getDefinition('fos_rest.exception_listener')->getArgument(0) - ) { - if (isset($container->getParameter('kernel.bundles')['TwigBundle']) && ($container->has('templating.engine.twig') || $container->has('twig'))) { - // only use this when TwigBundle is enabled and the deprecated SF templating integration is used - $controller = 'fos_rest.exception.twig_controller::showAction'; - } else { - $controller = 'fos_rest.exception.controller::showAction'; - } - - $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $controller); - } - - if (!$container->has('templating.engine.twig')) { - if ($container->has('twig') && $container->has('fos_rest.exception.twig_controller')) { - $container->findDefinition('fos_rest.exception.twig_controller')->replaceArgument(3, $container->findDefinition('twig')); - } else { - $container->removeDefinition('fos_rest.exception.twig_controller'); - } - } - } -} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 2da379692..4f12c3f36 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -431,21 +431,7 @@ private function addExceptionSection(ArrayNodeDefinition $rootNode) ->addDefaultsIfNotSet() ->canBeEnabled() ->children() - ->scalarNode('exception_controller') - ->defaultValue(static function () { - @trigger_error('Not setting the "fos_rest.exception.exception_controller" configuration option is deprecated since FOSRestBundle 2.8. Its default value will be set to "fos_rest.exception.controller::showAction" in 3.0.', E_USER_DEPRECATED); - - return null; - }) - ->validate() - ->ifTrue(static function ($v) { return null === $v; }) - ->then(static function ($v) { - @trigger_error('Not setting the "fos_rest.exception.exception_controller" configuration option is deprecated since FOSRestBundle 2.8. Its default value will be set to "fos_rest.exception.controller::showAction" in 3.0.', E_USER_DEPRECATED); - - return $v; - }) - ->end() - ->end() + ->scalarNode('exception_controller')->defaultValue('fos_rest.exception.controller::showAction')->end() ->scalarNode('service')->defaultNull()->end() ->arrayNode('codes') ->useAttributeAsKey('name') diff --git a/DependencyInjection/FOSRestExtension.php b/DependencyInjection/FOSRestExtension.php index bec0ac189..02b4f3738 100644 --- a/DependencyInjection/FOSRestExtension.php +++ b/DependencyInjection/FOSRestExtension.php @@ -351,9 +351,7 @@ private function loadException(array $config, XmlFileLoader $loader, ContainerBu $service->clearTag('kernel.event_subscriber'); } - $controller = $config['exception']['exception_controller'] ?? null; - - $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $controller); + $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $config['exception']['exception_controller']); $container->getDefinition('fos_rest.exception.codes_map') ->replaceArgument(0, $config['exception']['codes']); diff --git a/FOSRestBundle.php b/FOSRestBundle.php index db23512b7..5166a71ea 100644 --- a/FOSRestBundle.php +++ b/FOSRestBundle.php @@ -17,7 +17,6 @@ use FOS\RestBundle\DependencyInjection\Compiler\JMSHandlersPass; use FOS\RestBundle\DependencyInjection\Compiler\FormatListenerRulesPass; use FOS\RestBundle\DependencyInjection\Compiler\SerializerConfigurationPass; -use FOS\RestBundle\DependencyInjection\Compiler\TwigExceptionPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -38,8 +37,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new SerializerConfigurationPass()); $container->addCompilerPass(new ConfigurationCheckPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -10); $container->addCompilerPass(new FormatListenerRulesPass()); - // must run after \Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass which removes the templating.engine.twig service when templating is not enabled - $container->addCompilerPass(new TwigExceptionPass(), PassConfig::TYPE_BEFORE_REMOVING, -10); $container->addCompilerPass(new JMSFormErrorHandlerPass()); $container->addCompilerPass(new JMSHandlersPass(), PassConfig::TYPE_BEFORE_REMOVING, -10); $container->addCompilerPass(new HandlerRegistryDecorationPass(), PassConfig::TYPE_AFTER_REMOVING); diff --git a/Resources/config/exception_listener.xml b/Resources/config/exception_listener.xml index db099c57d..2f2dc1fa7 100644 --- a/Resources/config/exception_listener.xml +++ b/Resources/config/exception_listener.xml @@ -19,11 +19,6 @@ - - - The "%service_id%" service is deprecated since FOSRestBundle 2.8. - - diff --git a/Resources/doc/4-exception-controller-support.rst b/Resources/doc/4-exception-controller-support.rst index f432c5308..05dba8d95 100644 --- a/Resources/doc/4-exception-controller-support.rst +++ b/Resources/doc/4-exception-controller-support.rst @@ -21,15 +21,6 @@ configuration: The FOSRestBundle ExceptionController is executed before the one of the TwigBundle. -.. note:: - - FOSRestBundle defines two services for exception rendering, by default it - configures ``fos_rest.exception.controller`` which only supports rendering - via a serializer. In case no explicit controller is configured by the user - and TwigBundle is detected it will automatically configure - ``fos_rest.exception.twig_controller`` which additionally also supports - rendering via Twig. - To map Exception classes to HTTP response status codes an *exception map* may be configured, where the keys match a fully qualified class name and the values are either an integer HTTP response status code or a string matching a class diff --git a/Tests/Functional/app/AllowedMethodsListener/config.yml b/Tests/Functional/app/AllowedMethodsListener/config.yml index 9892bb985..7f6103eb0 100644 --- a/Tests/Functional/app/AllowedMethodsListener/config.yml +++ b/Tests/Functional/app/AllowedMethodsListener/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/sensio_framework_extra.yml } framework: diff --git a/Tests/Functional/app/Configuration/config.yml b/Tests/Functional/app/Configuration/config.yml index 83b9d5400..731754cd4 100644 --- a/Tests/Functional/app/Configuration/config.yml +++ b/Tests/Functional/app/Configuration/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/sensio_framework_extra.yml } - { resource: security.php } diff --git a/Tests/Functional/app/Debug/config.yml b/Tests/Functional/app/Debug/config.yml index 1c02bba17..bfa20f529 100644 --- a/Tests/Functional/app/Debug/config.yml +++ b/Tests/Functional/app/Debug/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/exception_listener.yml } fos_rest: diff --git a/Tests/Functional/app/JMSSerializer/config.yml b/Tests/Functional/app/JMSSerializer/config.yml index a838a36a4..a38049a01 100644 --- a/Tests/Functional/app/JMSSerializer/config.yml +++ b/Tests/Functional/app/JMSSerializer/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/exception_listener.yml } fos_rest: diff --git a/Tests/Functional/app/ParamFetcher/config.yml b/Tests/Functional/app/ParamFetcher/config.yml index 57c3d4a6a..80afde5e8 100644 --- a/Tests/Functional/app/ParamFetcher/config.yml +++ b/Tests/Functional/app/ParamFetcher/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/sensio_framework_extra.yml } parameters: diff --git a/Tests/Functional/app/RequestBodyParamConverter/config.yml b/Tests/Functional/app/RequestBodyParamConverter/config.yml index 2abb7d3e7..6761c494d 100644 --- a/Tests/Functional/app/RequestBodyParamConverter/config.yml +++ b/Tests/Functional/app/RequestBodyParamConverter/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/sensio_framework_extra.yml } framework: diff --git a/Tests/Functional/app/RequestBodyParamConverterFrameworkBundle/config.yml b/Tests/Functional/app/RequestBodyParamConverterFrameworkBundle/config.yml index 07062aef2..dffa3852e 100644 --- a/Tests/Functional/app/RequestBodyParamConverterFrameworkBundle/config.yml +++ b/Tests/Functional/app/RequestBodyParamConverterFrameworkBundle/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/sensio_framework_extra.yml } framework: diff --git a/Tests/Functional/app/Routing/config.yml b/Tests/Functional/app/Routing/config.yml index 55c429ea4..0235ab832 100644 --- a/Tests/Functional/app/Routing/config.yml +++ b/Tests/Functional/app/Routing/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } framework: serializer: diff --git a/Tests/Functional/app/Serializer/config.yml b/Tests/Functional/app/Serializer/config.yml index 6089ebc40..b74bd764a 100644 --- a/Tests/Functional/app/Serializer/config.yml +++ b/Tests/Functional/app/Serializer/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/exception_listener.yml } framework: diff --git a/Tests/Functional/app/Version/config.yml b/Tests/Functional/app/Version/config.yml index d8744f0e8..0ea584099 100644 --- a/Tests/Functional/app/Version/config.yml +++ b/Tests/Functional/app/Version/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/sensio_framework_extra.yml } framework: diff --git a/Tests/Functional/app/ViewResponseListener/config.yml b/Tests/Functional/app/ViewResponseListener/config.yml index 9368476e2..6f77e64d8 100644 --- a/Tests/Functional/app/ViewResponseListener/config.yml +++ b/Tests/Functional/app/ViewResponseListener/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config/default.yml } - - { resource: ../config/default.php } - { resource: ../config/sensio_framework_extra.yml } framework: diff --git a/Tests/Functional/app/config/default.php b/Tests/Functional/app/config/default.php deleted file mode 100644 index 074a6bdfb..000000000 --- a/Tests/Functional/app/config/default.php +++ /dev/null @@ -1,7 +0,0 @@ -loadFromExtension('fos_rest', [ - 'exception' => [ - 'exception_controller' => 'fos_rest.exception.controller::showAction', - ], -]);