HttpConfigRequestController.php in HTTP Client Manager 8
File
src/Controller/HttpConfigRequestController.php
View source
<?php
namespace Drupal\http_client_manager\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\http_client_manager\Entity\HttpConfigRequest;
use Drupal\vardumper\VarDumper\VarDumperDebug;
use Symfony\Component\DependencyInjection\ContainerInterface;
class HttpConfigRequestController extends ControllerBase {
protected $varDumper;
public function __construct(VarDumperDebug $varDumper = NULL) {
$this->varDumper = $varDumper;
}
public static function create(ContainerInterface $container) {
return new static($container
->has('vardumper_message') ? $container
->get('vardumper_message') : NULL);
}
public function execute($serviceApi, $commandName, $http_config_request) {
$storage = $this
->entityTypeManager()
->getStorage('http_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>',
],
],
];
}
}