You are here

CsvSubscriber.php in CSV Serialization 8.2

Same filename and directory in other branches
  1. 8 src/EventSubscriber/CsvSubscriber.php

File

src/EventSubscriber/CsvSubscriber.php
View source
<?php

namespace Drupal\csv_serialization\EventSubscriber;

use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Event subscriber for adding CSV content types to the request.
 */
class CsvSubscriber implements EventSubscriberInterface {

  /**
   * Register content type formats on the request object.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
   *   The Event to process.
   */
  public function onKernelRequest(GetResponseEvent $event) {
    $event
      ->getRequest()
      ->setFormat('csv', [
      'text/csv',
    ]);
  }

  /**
   * Implements \Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents().
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = [
      'onKernelRequest',
    ];
    return $events;
  }

}

Classes

Namesort descending Description
CsvSubscriber Event subscriber for adding CSV content types to the request.