You are here

HttpClientManagerEventSubscriber.php in HTTP Client Manager 8

File

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

namespace Drupal\http_client_manager\EventSubscriber;

use Drupal\http_client_manager\HttpClientInterface;
use Guzzle\Service\Command\OperationCommand;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Guzzle\Common\Event;

/**
 * Class HttpClientManagerEventSubscriber.
 *
 * @package Drupal\conftool
 */
class HttpClientManagerEventSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    return [
      'command.before_prepare' => array(
        'onCommandBeforePrepare',
        -9000,
      ),
    ];
  }

  /**
   * Command before-prepare event handler
   *
   * @param \Guzzle\Common\Event $event
   *   Event received
   */
  public function onCommandBeforePrepare(Event $event) {

    /** @var OperationCommand $command */
    $command = $event['command'];
    $description = $command
      ->getClient()
      ->getDescription();
    $command
      ->set(OperationCommand::HEADERS_OPTION, [
      HttpClientInterface::HEADER_API => $description
        ->getName(),
      HttpClientInterface::HEADER_COMMAND => $command
        ->getName(),
    ]);
  }

}

Classes

Namesort descending Description
HttpClientManagerEventSubscriber Class HttpClientManagerEventSubscriber.