You are here

public function HttpConfigRequestController::execute in HTTP Client Manager 8

Same name and namespace in other branches
  1. 8.2 src/Controller/HttpConfigRequestController.php \Drupal\http_client_manager\Controller\HttpConfigRequestController::execute()

Execute an Http Config Request.

Parameters

string $serviceApi: The Http Service Api name.

string $commandName: The Http Service Api Command name.

string $http_config_request: The Http Config Request name.

Return value

array A render array of the Request execution.

File

src/Controller/HttpConfigRequestController.php, line 56

Class

HttpConfigRequestController
Class HttpConfigRequestController.

Namespace

Drupal\http_client_manager\Controller

Code

public function execute($serviceApi, $commandName, $http_config_request) {
  $storage = $this
    ->entityTypeManager()
    ->getStorage('http_config_request');

  /** @var HttpConfigRequest $config_request */
  $config_request = $storage
    ->load($http_config_request);
  $request = [
    'serviceApi' => $serviceApi,
    'commandName' => $commandName,
    'parameters' => array_filter($config_request
      ->getParameters()),
  ];
  $response = $config_request
    ->execute();
  if ($this->varDumper) {
    $this->varDumper
      ->dump($request, 'REQUEST: ' . $http_config_request);
    $this->varDumper
      ->dump($response, 'RESPONSE: ' . $http_config_request);
    return [
      '#type' => 'markup',
      '#markup' => '',
    ];
  }
  return [
    'request' => [
      '#type' => 'fieldset',
      '#title' => 'REQUEST: ' . $http_config_request,
      'output' => [
        '#markup' => '<pre>' . print_r($request, TRUE) . '</pre>',
      ],
    ],
    'response' => [
      '#type' => 'fieldset',
      '#title' => 'RESPONSE: ' . $http_config_request,
      'output' => [
        '#markup' => '<pre>' . print_r($response, TRUE) . '</pre>',
      ],
    ],
  ];
}