首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Solarium客户端中参数2的TypeError

Solarium客户端中参数2的TypeError
EN

Stack Overflow用户
提问于 2021-06-10 07:57:48
回答 2查看 195关注 0票数 0

我正在尝试使用Search_api_solr v4.1、SolariaV6.0和symfony/event-dispatcher v3.4.47启动一个客户端,但我一直收到一个TypeError。

代码语言:javascript
复制
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

我不太明白为什么它需要一个Psr\EventDispatcher\EventDispatcherInterface的实例,而所有关于solarium的文档都说要使用Symfony\Component\EventDispatcher\EventDispatcher.

我的适配器和事件分派器如下所示

代码语言:javascript
复制
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();
}

有没有其他人遇到过这个问题,或者知道解决这个问题的方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-07-03 05:04:20

当您在new Client()上创建日光客户端时,第二个参数要求您提供一个实现Psr\EventDispatcher\EventDispatcherInterface的类。但是,在use语句中,您要创建的EventDispatcher是Symfony\Component\EventDispatcher\EventDispatcher

将use语句更改为PSR事件分派器,就可以了。

票数 1
EN

Stack Overflow用户

发布于 2021-06-10 15:37:35

当您深入研究Symfony源代码时,可以查看以下内容:

代码语言:javascript
复制
if (interface_exists(PsrEventDispatcherInterface::class)) {
    /**
     * Allows providing hooks on domain-specific lifecycles by dispatching events.
     */
    interface EventDispatcherInterface extends PsrEventDispatcherInterface
    {
        /**
         * Dispatches an event to all registered listeners.
         *
         * For BC with Symfony 4, the $eventName argument is not declared explicitly on the
         * signature of the method. Implementations that are not bound by this BC constraint
         * MUST declare it explicitly, as allowed by PHP.
         *
         * @param object      $event     The event to pass to the event handlers/listeners
         * @param string|null $eventName The name of the event to dispatch. If not supplied,
         *                               the class of $event should be used instead.
         *
         * @return object The passed $event MUST be returned
         */
        public function dispatch($event/*, string $eventName = null*/);
    }
} else {
    /**
     * Allows providing hooks on domain-specific lifecycles by dispatching events.
     */
    interface EventDispatcherInterface
    {
        /**
         * Dispatches an event to all registered listeners.
         *
         * For BC with Symfony 4, the $eventName argument is not declared explicitly on the
         * signature of the method. Implementations that are not bound by this BC constraint
         * MUST declare it explicitly, as allowed by PHP.
         *
         * @param object      $event     The event to pass to the event handlers/listeners
         * @param string|null $eventName The name of the event to dispatch. If not supplied,
         *                               the class of $event should be used instead.
         *
         * @return object The passed $event MUST be returned
         */
        public function dispatch($event/*, string $eventName = null*/);
    }
}

所以你的问题是interface_exists(PsrEventDispatcherInterface::class)返回false。THis接口来自这个包https://packagist.org/packages/psr/event-dispatcher,所以我会尝试使用composer require psr/event-dispatcher来修复它。

编辑:您的symfony事件调度程序版本已过时。请更新到5.3以解决此问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67913020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档