2014-02-18 32 views
1

我想創建一個手動提供程序來手動填充我的FOS Elastica索引以解釋一些複雜的聯接。目前,我只是想讓提供者在沒有連接的情況下工作,並且我無法在提供者的構造函數中注入正確的Elastica Type。這裏是我的供應商的構造函數:FOS 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文件中的正確參數?或者問題可能完全是其他問題?

回答

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 
+0

嗯,你的解決方案不適合我。鑑於我下面的yaml文件,你知道什麼是正確的語法? – DIMMSum

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 } 

由於任何人誰正在考慮幫助我這個相當基本的問題。