Question

I am trying to create a manual provider to manually populate my FOS Elastica index to account for some complex joins. At the moment, I am just trying to get the provider to work even without the joins, and I am having trouble injecting the correct Elastica Type into my constructor for the provider. Here is the constructor of my provider:

// ...
class EmpPosDeptProvider implements ProviderInterface
{

    private $em;
    protected $type;

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

and here is my services.yml file:

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

When I try to execute php app/console fos:elastica:populate I am receiving the following error:

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

Does anyone know what I need to give as a correct argument in my services.yml file? Or could the problem be something else entirely?

Was it helpful?

Solution

You're passing a string containing Ccit\EmployeesBundle\Search\EmpPosDeptProvider. You have to pass an instance of EmpPosDeptProvider, and it may be declared in your services.yml something like:

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

OTHER TIPS

Apparently I needed to provide the explicit path to the type I was referencing. The following line worked:

@fos_elastica.index.employees.employeePositionDepartment

This makes sense given that my config.yml file contains the following:

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 }

Thanks to anyone who was considering helping me with this rather elementary question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top