gbprod/elastica-bundle

该包已废弃,不再维护。未建议替代包。

用于在Symfony应用中使用Elastica的简单捆绑包

安装次数: 19,282

依赖者: 0

建议者: 1

安全: 0

星标: 4

关注者: 2

分支: 0

公开问题: 1

类型:捆绑包

v1.2.0 2018-02-05 15:39 UTC

This package is auto-updated.

Last update: 2021-08-07 10:50:05 UTC


README

Build Status codecov Scrutinizer Code Quality Dependency Status

Latest Stable Version Total Downloads Latest Unstable Version License

这是一个用于在Symfony应用中使用elastica的简单捆绑包。允许你在Symfony应用中创建elastica服务。目标是创建一个轻量级的FOSElasticaBundle替代品,因为有时我们不需要那么多东西。

安装

使用composer下载捆绑包

composer require gbprod/elastica-bundle

app/AppKernel.php文件中声明

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new GBProd\ElasticaBundle\ElasticaBundle(),
        // ...
    );
}

配置

客户端

# app/config/config.yml
elastica:
    clients:
        default:
            host: 127.0.0.1
            port: 9200
        other_client:
            host: 127.0.0.1
            port: 9201

如果使用集群

# app/config/config.yml
elastica:
    clients:
        default:
            connections:
                - { host: localhost, port: 9200 }
                - { host: localhost, port: 9201 }

可用选项:hostportpathurlproxytransportpersistenttimeoutproxy

自定义日志记录器

默认情况下,此捆绑包使用Symfony的默认日志记录器(@logger)在elastica通道中记录查询。

您可以使用logger配置选项使用自定义日志记录器。

# app/config/config.yml
elastica:
    logger: my_custom_logger_service_id
    clients:
        default:
            host: 127.0.0.1
            port: 9200

使用

现在您可以使用服务elastica.default_clientelastica.my_other_client

$client = $container->get('elastica.default_client');

服务自动注入支持

Symfony 3.3引入了对服务自动注入的支持。要能够将Elastica连接自动注入到您的服务中,您需要将具有名称default客户端配置设置。如果您有多个连接,则只有default连接将启用自动注入,因为服务自动注入是通过类名解析的。

默认情况下启用自动注入支持,但如果您出于某种原因需要禁用它,可以设置autowire: false参数。

# app/config/config.yml
elastica:
    autowire: false
    clients:
        default:
            host: 127.0.0.1
            port: 9200

测试

克隆此存储库(或一个分支)。您应该安装php>=5.6composer

make test-unit

贡献

请随时贡献,有关更多信息,请参阅CONTRIBUTING.md文件。