You are here

class AcceptNegotiation406 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php \Drupal\Core\EventSubscriber\AcceptNegotiation406

View subscriber rendering a 406 if we could not route or render a request.

@todo fix or replace this in https://www.drupal.org/node/2364011

Hierarchy

Expanded class hierarchy of AcceptNegotiation406

1 string reference to 'AcceptNegotiation406'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses AcceptNegotiation406
accept_negotiation_406 in core/core.services.yml
Drupal\Core\EventSubscriber\AcceptNegotiation406

File

core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php, line 20
Contains \Drupal\Core\EventSubscriber\AcceptNegotiation406.

Namespace

Drupal\Core\EventSubscriber
View source
class AcceptNegotiation406 implements EventSubscriberInterface {

  /**
   * Throws an HTTP 406 error if we get this far, which we normally shouldn't.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
   *   The event to process.
   */
  public function onViewDetect406(GetResponseForControllerResultEvent $event) {
    $request = $event
      ->getRequest();
    $result = $event
      ->getControllerResult();

    // If this is a render array then we assume that the router went with the
    // generic controller and not one with a format. If the format requested is
    // not HTML though we can also assume that the requested format is invalid
    // so we provide a 406 response.
    if (is_array($result) && $request
      ->getRequestFormat() !== 'html') {
      throw new NotAcceptableHttpException('Not acceptable');
    }
  }

  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    $events[KernelEvents::VIEW][] = [
      'onViewDetect406',
      -10,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcceptNegotiation406::getSubscribedEvents static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
AcceptNegotiation406::onViewDetect406 public function Throws an HTTP 406 error if we get this far, which we normally shouldn't.