php - Symfony4.4: CSV output is not possible

one text

I updated the app from Symfony 3.4 to 4.4 and verified the operation.
The function to output csv does not work, and when I press the button, the page redirects.
It is implemented by the method of the link below, but the official document is only up to 4.2.
Is there an alternative to 4.2 or later?

https://symfony.com/doc/4.1/templating/formats.html

Controller

    /**
     * @Route("/", defaults={"_format"="html"}, requirements={"_format"="html|csv"})
     * @Method("GET")
     *
     * @Template("@AppBundle/Hq/Post/index.html.twig")
     */
    public function indexAction(Request $request)
    {
        if ($request->getRequestFormat() == 'html') {
            // At the time of html output
        } elseif ($request->getRequestFormat() == 'csv') {
            // At the time of csv output
            // Set file name, no pagination
            $request->attributes->set('filename', 'post_article.csv');
        }

index.html.twig

    <button type="submit" class="btn" name="_format" value="csv">
        <i class="icon-download"></i> CSV output
    </button>

CsvListener

class CsvResponseListener
{
    /**
     * kernel.response Set the response at the time of CSV output in the event
     */
    public function onKernelResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();

        // Set the response at the time of CSV output in the event
        if ($request->getRequestFormat() === 'csv' && $response->getStatusCode() == 200) {
            // Convert response body to CRLF, SJIS-WIN
            $content = str_replace("\n", "\r\n", $response->getContent());
            $content = mb_convert_encoding($content, 'SJIS-WIN', 'UTF-8');
            $response->setContent($content);

            // Get the file name
            $filename = $request->attributes->get('filename', 'download.csv');

            // Set header for file download
            $response->headers->set('Content-Type', 'application/octet-stream');
            $response->headers->set('Content-Transfer-Encoding', 'binary');
            $response->headers->set('Content-Disposition', 'attachment; filename="'.$filename.'"');
            $response->headers->set('Content-Length', strlen(bin2hex($content)) / 2);
        }
    }
}

services.yaml

    app.listener.csvResponseListener:
        class: AppBundle\Listener\CsvResponseListener
        tags:
            - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }

Source