0

我正在尝试创建一个手动提供程序来手动填充我的 FOS Elastica 索引以解决一些复杂的连接问题。目前,我只是想让提供者在没有连接的情况下也能正常工作,并且在将正确的 Elastica 类型注入到提供者的构造函数中时遇到了麻烦。这是我的提供者的构造函数:

// ...
class EmpPosDeptProvider implements ProviderInterface
{

    private $em;
    protected $type;

    public function __construct(Type $type, EntityManager $em)
    {
        $this->type = $type;
        $this->em = $em->getRepository('CcitEmployeesBundle:Position');
    }
// ...

这是我的 services.yml 文件:

services:
    employees.search_provider.empPosDept:
        class: Ccit\EmployeesBundle\Search\EmpPosDeptProvider
        tags:
            - { name: fos_elastica.provider, index: employees, type: empPosDept }
        arguments:
            - %fos_elastica.type.class%
            - @doctrine.orm.entity_manager

当我尝试执行php app/console fos:elastica:populate时,我收到以下错误:

PHP Catchable fatal error:  Argument 1 passed to Ccit\EmployeesBundle\Search
\EmpPosDeptProvider::__construct() must be an instance of Elastica\Type, string given, 
called in /vagrant-nfs/employees/app/cache/dev/appDevDebugProjectContainer.php on line 736 
and defined in /vagrant-nfs/employees/src/Ccit/EmployeesBundle/Search
/EmpPosDeptProvider.php on line 23

有谁知道我需要在我的 services.yml 文件中提供什么作为正确参数?或者问题可能完全是其他问题?

4

2 回答 2

2

您正在传递一个包含Ccit\EmployeesBundle\Search\EmpPosDeptProvider. 你必须传递一个实例EmpPosDeptProvider,它可以在你的services.yml东西中声明,比如:

services:
    fos_elastica.type:
        class: %fos_elastica.type.class%

    employees.search_provider.empPosDept:
        class: Ccit\EmployeesBundle\Search\EmpPosDeptProvider
        tags:
            - { name: fos_elastica.provider, index: employees, type: empPosDept }
        arguments:
            - @fos_elastica.type
            - @doctrine.orm.entity_manager
于 2014-02-18T20:49:24.523 回答
0

显然我需要提供我所引用的类型的显式路径。以下行有效:

@fos_elastica.index.employees.employeePositionDepartment

这是有道理的,因为我的 config.yml 文件包含以下内容:

fos_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    employees:
        client: default
        types:
            employeePositionDepartment:
                mappings:
                    id: { type: integer }
                    title: { type: string }
                    startDate: { type: date, format: date_time_no_millis }
                    endDate: { type: date, format: date_time_no_millis }
                    supervisor: { type: integer }

感谢任何考虑帮助我解决这个相当基本问题的人。

于 2014-02-18T20:51:14.110 回答