Служба "fos_elastica.finder.app.user" не найдена - PullRequest
0 голосов
/ 12 января 2019

Symfony не может найти сервис для fos_elastica

Service "fos_elastica.finder.app.user" not found: even though it exists in the app's container, the container inside "App\Controller\DevController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "session" and "twig" services. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "DevController::getSubscribedServices()".

мой конфиг

# Read the documentation: https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/Resources/doc/setup.md
fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }
#    indexes:
#        app: ~
    indexes:
        app:
            client: default
            types:
                user:
                    properties:
                        username: ~
#                    mappings:
#                        email: ~
                    persistence:
                        # the driver can be orm, mongodb, phpcr or propel
                        # listener and finder are not supported by
                        # propel and should be removed
                        driver: orm
                        model: App\Entity\User
                        provider: ~
                        listener: ~
                        finder: ~

мой контроллер:

    /**
     * @Route("/search")
     */
    public function searchElastic(){
        /** var array of App\Entity\User */
        $finder = $this->container->get('fos_elastica.finder.app.user');
        return new response('N/A');
    }

команда php bin/console fos:elastica:populate не выдавала никаких ошибок и в phpstorm она не подсвечивается (это означает, что phpstorm нашел ее)

Пожалуйста, помогите мне.

1 Ответ

0 голосов
/ 12 января 2019

Вы должны использовать инъекцию зависимости следующим образом:

Добавьте use оператор в класс контроллера use FOS\ElasticaBundle\Manager\RepositoryManagerInterface;, тогда ваше действие должно выглядеть так:

/**
 * @Route("/search")
 */
public function searchElastic(RepositoryManagerInterface $finder) {

    $someResult = $finder->getRepository(User::class)->find(...);
    return new response('N/A');
}
...