symfonydrupaldrupal-8solarium

TypeError for Argument 2 in Solarium Client


I'm trying to start a client using Search_api_solr v4.1, Solarium v6.0 and symfony/event-dispatcher v3.4.47 but I keep getting a TypeError.

TypeError: Argument 2 passed to Solarium\Core\Client\Client::__construct() 
must be an instance of Psr\EventDispatcher\EventDispatcherInterface, 
instance of Symfony\Component\EventDispatcher\EventDispatcher given

I'm not quite sure why it's expecting an instance of Psr\EventDispatcher\EventDispatcherInterface when all the documentation on solarium says to use Symfony\Component\EventDispatcher\EventDispatcher.

My adapter and event Dispatcher is as below

use Solarium\Client;
use Solarium\Core\Client\Adapter\Curl;
use Symfony\Component\EventDispatcher\EventDispatcher; 

function get_search_query() {
$adapter = new Curl();
$eventDispatcher = new EventDispatcher();

$config = ['endpoint' => ['localhost' => [
                'host' => $id,
                'port' => $port,
                'path' => '/',
                'collection' => '$core',],],];

$search = new Client($adapter, $eventDispatcher, $config);
$query = $search->createSelect();
}

Has anyone else ran into this issue or knows a fix for this?


Solution

  • When you are creating the solarium client at new Client() the second parameter expects you to give a class implementing Psr\EventDispatcher\EventDispatcherInterface. However, in your use statement the EventDispatcher you are creating is Symfony\Component\EventDispatcher\EventDispatcher.

    Change the use statement to the PSR event dispatcher and you should be fine.