From 3c1aac883d872211c557599f833f58e11ba24fbf Mon Sep 17 00:00:00 2001 From: Tom Stovall <119924+stovak@users.noreply.github.com> Date: Wed, 3 Nov 2021 13:31:26 -0700 Subject: [PATCH 1/3] backporting to d8 --- composer.json | 3 ++- src/Events/PantheonEventDispatcher.php | 26 ++++++++++++++++++++++++++ src/Services/SolariumClient.php | 4 ++-- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/Events/PantheonEventDispatcher.php diff --git a/composer.json b/composer.json index c93374fc..5c197bfb 100644 --- a/composer.json +++ b/composer.json @@ -41,8 +41,9 @@ "drupal/search_api_solr": "^4.2.1", "guzzlehttp/guzzle": "^6", "http-interop/http-factory-guzzle": "^1.0", + "kint-php/kint": "@stable", "php-http/guzzle6-adapter": "^2.0", - "kint-php/kint": "@stable" + "psr/event-dispatcher": "^1.0" }, "require-dev": { "consolidation/robo": "^3.0", diff --git a/src/Events/PantheonEventDispatcher.php b/src/Events/PantheonEventDispatcher.php new file mode 100644 index 00000000..fb56b05b --- /dev/null +++ b/src/Events/PantheonEventDispatcher.php @@ -0,0 +1,26 @@ +listeners)){ + return []; + } + + return parent::getListeners( + $eventName + ); + } + +} diff --git a/src/Services/SolariumClient.php b/src/Services/SolariumClient.php index 7e3ee566..de92eff6 100644 --- a/src/Services/SolariumClient.php +++ b/src/Services/SolariumClient.php @@ -2,13 +2,13 @@ namespace Drupal\search_api_pantheon\Services; +use Drupal\search_api_pantheon\Events\PantheonEventDispatcher; use Psr\Log\LoggerAwareTrait; use Solarium\Core\Client\Client; use Solarium\Core\Client\Request; use Solarium\Core\Client\Response; use Solarium\Core\Query\QueryInterface; use Solarium\Core\Query\Result\ResultInterface; -use Symfony\Component\EventDispatcher\EventDispatcher; use Drupal\Core\Logger\LoggerChannelFactoryInterface; /** @@ -23,7 +23,7 @@ class SolariumClient extends Client { public function __construct(PantheonGuzzle $guzzle, Endpoint $endpoint, LoggerChannelFactoryInterface $logger_factory) { parent::__construct( $guzzle->getPsr18Adapter(), - new EventDispatcher(), + new PantheonEventDispatcher(), ['endpoint' => [$endpoint]] ); $this->logger = $logger_factory->get('PantheonSolariumClient'); From 87f7cd51e421b0c1582649b97dbefd8d17266487 Mon Sep 17 00:00:00 2001 From: Tom Stovall <119924+stovak@users.noreply.github.com> Date: Wed, 3 Nov 2021 13:37:19 -0700 Subject: [PATCH 2/3] linting --- src/Events/PantheonEventDispatcher.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Events/PantheonEventDispatcher.php b/src/Events/PantheonEventDispatcher.php index fb56b05b..a490be93 100644 --- a/src/Events/PantheonEventDispatcher.php +++ b/src/Events/PantheonEventDispatcher.php @@ -6,18 +6,37 @@ use Psr\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyEventDispatcher; +/** + * Pantheon Event Dispatcher + */ class PantheonEventDispatcher extends SymfonyEventDispatcher implements EventDispatcherInterface { + /** + * @var array + */ protected $listeners = []; + + /** + * @var array + */ protected $sorted = []; + /** + * Override to fix issues with zero listeners. + * + * @param null $eventName + * Name of the Event in question. + * + * @return array|mixed + * Any listeners or empty array. + */ public function getListeners($eventName = NULL) { if (empty($this->listeners)){ return []; } - + return parent::getListeners( $eventName ); From e3e5a58365dfa9d64f1118d02bf7b25063c4aae9 Mon Sep 17 00:00:00 2001 From: Tom Stovall <119924+stovak@users.noreply.github.com> Date: Wed, 3 Nov 2021 13:46:38 -0700 Subject: [PATCH 3/3] linting --- src/Events/PantheonEventDispatcher.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Events/PantheonEventDispatcher.php b/src/Events/PantheonEventDispatcher.php index a490be93..538ece03 100644 --- a/src/Events/PantheonEventDispatcher.php +++ b/src/Events/PantheonEventDispatcher.php @@ -2,16 +2,13 @@ namespace Drupal\search_api_pantheon\Events; - use Psr\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyEventDispatcher; /** - * Pantheon Event Dispatcher + * Pantheon Event Dispatcher. */ -class PantheonEventDispatcher - extends SymfonyEventDispatcher - implements EventDispatcherInterface { +class PantheonEventDispatcher extends SymfonyEventDispatcher implements EventDispatcherInterface { /** * @var array @@ -27,13 +24,13 @@ class PantheonEventDispatcher * Override to fix issues with zero listeners. * * @param null $eventName - * Name of the Event in question. + * Name of the Event in question. * * @return array|mixed - * Any listeners or empty array. + * Any listeners or empty array. */ public function getListeners($eventName = NULL) { - if (empty($this->listeners)){ + if (empty($this->listeners)) { return []; }