Skip to content

Commit

Permalink
Fixing issues with Event Dispatcher
Browse files Browse the repository at this point in the history
restoring psr 18 code

d9 is EOL

restoring get Adapter

linting

adding import

adding factory
  • Loading branch information
stovak committed Jan 27, 2025
1 parent 5cb267e commit e2b1133
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"guzzlehttp/guzzle": "^7.5",
"guzzlehttp/psr7": "^2.7",
"kint-php/kint": "^5|^6",
"php-http/guzzle7-adapter": "^1.1",
"psr/event-dispatcher": "^1.0",
"symfony/finder": "^4.4|^5|^6|^7",
"symfony/yaml": "^4.4|^5|^6|^7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Search API Pantheon Admin
type: module
description: Administer a Pantheon Search server
core_version_requirement: ^9.4 || ^10 || ^11
core_version_requirement: ^10 || ^11
package: Search
dependencies:
- search_api_solr:search_api_solr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Search API Pantheon Examples
type: module
description: Contains some examples of things you could do with Search API Pantheon module. This module should not be enabled in prod.
core_version_requirement: ^9.4 || ^10 || ^11
core_version_requirement: ^10 || ^11
package: Search
dependencies:
- search_api_pantheon:search_api_pantheon
2 changes: 1 addition & 1 deletion search_api_pantheon.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Search API Pantheon
type: module
description: Search API + Solr + Pantheon integration
core_version_requirement: ^9.4 || ^10 || ^11
core_version_requirement: ^10 || ^11
package: Search
dependencies:
- search_api_solr:search_api_solr
1 change: 0 additions & 1 deletion src/Commands/Reload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\search_api_pantheon\Commands;

use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\search_api_pantheon\Services\PantheonGuzzle;
use Drupal\search_api_pantheon\Services\SchemaPoster;
use Drush\Commands\DrushCommands;
Expand Down
1 change: 0 additions & 1 deletion src/Commands/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\search_api_pantheon\Commands;

use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\search_api_pantheon\Plugin\SolrConnector\PantheonSolrConnector;
use Drupal\search_api_pantheon\Services\PantheonGuzzle;
use Drupal\search_api_pantheon\Services\SchemaPoster;
Expand Down
27 changes: 24 additions & 3 deletions src/Services/PantheonGuzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\search_api_pantheon\Services;

use GuzzleHttp\Psr7\HttpFactory;
use Drupal\search_api_pantheon\Traits\EndpointAwareTrait;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\CurlHandler;
Expand All @@ -13,8 +14,10 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Solarium\Core\Client\Adapter\AdapterInterface;
use Solarium\Core\Client\Adapter\Psr18Adapter;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Solarium\Core\Client\Endpoint;

/**
* Pantheon-specific extension of the Guzzle http query class.
Expand All @@ -23,8 +26,7 @@
*/
class PantheonGuzzle extends Client implements
ClientInterface,
LoggerAwareInterface,
AdapterInterface {
LoggerAwareInterface {
use LoggerAwareTrait;
use EndpointAwareTrait;

Expand All @@ -38,7 +40,11 @@ class PantheonGuzzle extends Client implements
/**
* Class Constructor.
*/
public function __construct(Endpoint $endpoint, LoggerChannelFactoryInterface $logger_factory, AccountProxyInterface $current_user) {
public function __construct(
Endpoint $endpoint,
LoggerChannelFactoryInterface $logger_factory,
AccountProxyInterface $current_user
) {
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(
Expand Down Expand Up @@ -160,4 +166,19 @@ public function requestUriAlterForPantheonEnvironment(RequestInterface $request)
return $request->withUri($uri);
}

/**
* Get a PSR adapter interface based on this class.
*
* @return \Solarium\Core\Client\Adapter\AdapterInterface
* The interface in question.
*/
public function getAdapter(): AdapterInterface {
$factory = new HttpFactory();
return new Psr18Adapter(
$this,
$factory,
$factory,
);
}

}
21 changes: 10 additions & 11 deletions src/Services/SolariumClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Query\Result\ResultInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\search_api_pantheon\Solarium\EventDispatcher\Psr14Bridge;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Customized Solrium Client to send Guzzle debugging to log entries.
Expand All @@ -21,18 +20,18 @@ class SolariumClient extends Client {
/**
* Class constructor.
*/
public function __construct(PantheonGuzzle $guzzle, Endpoint $endpoint, LoggerChannelFactoryInterface $logger_factory, EventDispatcher $event_dispatcher) {
public function __construct(
PantheonGuzzle $guzzle,
Endpoint $endpoint,
LoggerChannelFactoryInterface $logger_factory,
EventDispatcherInterface $event_dispatcher) {
$drupal_major_parts = explode('.', \Drupal::VERSION);
$drupal_major = reset($drupal_major_parts);
if ($drupal_major < 9) {
// Use the bridge only if Drupal 8.
$event_dispatcher = new Psr14Bridge($event_dispatcher);
}
parent::__construct(
$guzzle,
$event_dispatcher,
['endpoint' => [$endpoint]]
);
$guzzle->getAdapter(),
$event_dispatcher,
['endpoint' => [$endpoint]],
);
$this->logger = $logger_factory->get('PantheonSolariumClient');
$this->setDefaultEndpoint($endpoint);
}
Expand Down

0 comments on commit e2b1133

Please sign in to comment.