Commit bd84e468 authored by m4olivei's avatar m4olivei
Browse files

Issue #3066644 by m4olivei, anabpv: Fix PHPCS

parent 11d45f4b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ final class Forwarder extends ControllerBase {
  /**
   * The name of the query string parameter containing the URI.
   *
   * @param string
   * @var string
   */
  private $uriParamName;

@@ -53,7 +53,7 @@ final class Forwarder extends ControllerBase {
   *   The response object.
   */
  public function forward(HttpApiInterface $api_proxy, Request $request): Response {
    // TODO: This belongs to the routing system.
    // @todo This belongs to the routing system.
    $account = $this->currentUser();
    $cache_contexts = [
      'url.query_args:' . $this->uriParamName,
+3 −4
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\api_proxy\EventSubscriber;

use Drupal\api_proxy\Controller\Forwarder;
use Drupal\api_proxy\Plugin\HttpApiPluginBase;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\CacheableResponse;
@@ -36,7 +35,7 @@ class OptionsRequestSubscriber implements EventSubscriberInterface {
  /**
   * The name of the query string parameter containing the URI.
   *
   * @param string
   * @var string
   */
  private $uriParamName;

@@ -45,7 +44,7 @@ class OptionsRequestSubscriber implements EventSubscriberInterface {
   *
   * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider
   *   The route provider.
   * @param \Symfony\Component\EventDispatcher\EventSubscriberInterface
   * @param \Symfony\Component\EventDispatcher\EventSubscriberInterface $subject
   *   The decorated service.
   * @param string $uri_param_name
   *   The name of the query string parameter containing the URI.
@@ -117,7 +116,7 @@ class OptionsRequestSubscriber implements EventSubscriberInterface {
   * @return \Drupal\Core\Config\ImmutableConfig
   *   The immutable configuration object.
   *
   * @todo: use dependency injection to pass the configFactory.
   * @todo use dependency injection to pass the configFactory.
   */
  private function config(string $config_id): ImmutableConfig {
    return \Drupal::config($config_id);
+1 −1
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ final class SettingsForm extends ConfigFormBase {
    $message = $this->t('Settings saved for plugin(s): %names', [
      '%names' => implode(', ', array_map(function (HttpApiPluginBase $api_proxy) {
        return $api_proxy->getPluginDefinition()['label'];
      }, $api_proxies))
      }, $api_proxies)),
    ]);
    $this->messenger()->addStatus($message);
  }
+0 −1
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\api_proxy\ParamConverter;

use Drupal\api_proxy\Plugin\HttpApiInterface;
use Drupal\api_proxy\Plugin\HttpApiPluginBase;
use Drupal\api_proxy\Plugin\HttpApiPluginManager;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Http\Exception\CacheableNotFoundHttpException;
+105 −0
Original line number Diff line number Diff line
@@ -10,17 +10,122 @@ use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Defines a HttpApi plugin.
 */
interface HttpApiInterface extends PluginInspectionInterface {

  /**
   * Get the base URL for an HttpApi plugin, configured as the serviceUrl.
   *
   * @return string
   *   The base URL for the third party HTTP API.
   */
  public function getBaseUrl(): string;

  /**
   * Whether request headers should be forwarded on to the API.
   *
   * @return bool
   *   TRUE if we should forward request headers to the API, otherwise FALSE.
   */
  public function shouldForwardHeaders(): bool;

  /**
   * Get configured additional headers to send along to the API.
   *
   * @return array
   *   Array of headers, key being the name of the header, value being the value
   *   of the header.
   */
  public function getAdditionalHeaders(): array;

  /**
   * Should responses from the API be force cached?
   *
   * Responses are cached in Page Cache respecting the Cache-Control headers
   * from the 3rd party HTTP API by default. If caching is forced, cache in any
   * situation.
   *
   * @return int
   *   Value of one to indicate that caching should be forced, otherwise 0.
   */
  public function isCacheForced(): int;

  /**
   * Get the forced cache TTL.
   *
   * @return int
   *   Length of time to force cache the response from the API in seconds.
   */
  public function getForcedCacheTtl(): int;

  /**
   * Provides an opportunity to preprocess the incoming request.
   *
   * @param string $method
   *   The HTTP method.
   * @param string $uri
   *   Request URI.
   * @param \Symfony\Component\HttpFoundation\HeaderBag $headers
   *   Request headers.
   * @param \Symfony\Component\HttpFoundation\ParameterBag $query
   *   Query parameters from the incoming request.
   *
   * @return array
   *   Array including any adjustments to method, uri, headers, and query in the
   *   same positions as the arguments.
   */
  public function preprocessIncoming(string $method, string $uri, HeaderBag $headers, ParameterBag $query): array;

  /**
   * Opportunity to preprocess the Guzzle $options argument for the API request.
   *
   * @param array $options
   *   The options array that will be passed to
   *   \GuzzleHttp\ClientInterface::request.
   *
   * @return array
   *   An $options array that will be passed along to
   *   \GuzzleHttp\ClientInterface::request.
   *
   * @see \GuzzleHttp\ClientInterface::request
   */
  public function preprocessOutgoingRequestOptions(array $options): array;

  /**
   * Opportunity to adjust the response that came back from the API.
   *
   * @param \Symfony\Component\HttpFoundation\Response $response
   *   The response that came back from the third party HTTP API.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   Adjusted reponse object that will be passed back to the end user.
   */
  public function postprocessOutgoing(Response $response): Response;

  /**
   * Forward an incoming request to the third party API endpoint at $uri.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   Incoming request.
   * @param string $uri
   *   Requested uri on the third party HTTP API.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   Response back from the third party API.
   */
  public function forward(Request $request, string $uri): Response;

  /**
   * Send the CORS response to the given HTTP OPTIONS request.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   An HTTP OPTION request for getting CORS headers.
   *
   * @return \Drupal\Core\Cache\CacheableResponse
   *   Response with all the pertinent CORS headers.
   */
  public function corsResponse(Request $request): CacheableResponse;

  /**
Loading