fsi/datasource-elastica-driver

v0.5.0 2017-02-10 09:49 UTC

README

Experimental DataSource Driver for ElasticSearch

Requirements

This driver requires ES ^2.0

Use in Symfony2 Application

Service definition (elastica-driver.xml):

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <parameters>
        <parameter key="datasource.driver.extension.class">FSi\Component\DataSource\Extension\Symfony\DependencyInjection\Driver\DriverExtension</parameter>
        <parameter key="datasource.driver.elastica.factory.class">FSi\Component\DataSource\Driver\Elastica\ElasticaDriverFactory</parameter>
    </parameters>

    <services>
        <service id="datasource.driver.factory.manager" class="%datasource.driver.factory.manager.class%">
            <argument type="collection">
                <argument type="service" id="datasource.driver.doctrine.factory" />
                <argument type="service" id="datasource.driver.collection.factory" />
                <argument type="service" id="datasource.driver.elastica.factory" />
            </argument>
        </service>

        <!-- DataSource Elastica Extensions -->
        <service id="datasource.driver.elastica.extension" class="%datasource.driver.extension.class%">
            <argument type="service" id="service_container" />
            <argument type="string">elastica</argument>
            <!-- All services with tag "datasource.driver.elastica.field" are inserted here by DataSourcePass -->
            <argument type="collection" />
            <!-- All services with tag "datasource.driver.elastica.field.subscriber" are inserted here by DataSourcePass -->
            <argument type="collection" />
            <!-- All services with tag "datasource.driver.elastica.subscriber" are inserted here by DataSourcePass -->
            <argument type="collection" />
            <tag name="datasource.driver.extension" alias="elastica" />
        </service>

        <!-- DataSource Elastica Factory -->
        <service id="datasource.driver.elastica.factory" class="%datasource.driver.elastica.factory.class%">
            <argument type="collection">
                <!--
                We don't need to be able to add more extensions.
                 * more fields can be registered with the datasource.driver.elastica.field tag
                 * more field subscribers can be registered with the datasource.driver.elastica.field.subscriber tag
                 * more listeners can be registered with the datasource.listener tag
                -->
                <argument type="service" id="datasource.driver.elastica.extension" />
            </argument>
            <tag name="datasource.driver.factory"/>
        </service>

        <!-- DataSource Elastica CoreExtensions -->
        <service id="datasource.driver.elastica.field.date" class="FSi\Component\DataSource\Driver\Elastica\Extension\Core\Field\Date">
            <tag name="datasource.driver.elastica.field" alias="date" />
        </service>
        <service id="datasource.driver.elastica.field.datetime" class="FSi\Component\DataSource\Driver\Elastica\Extension\Core\Field\DateTime">
            <tag name="datasource.driver.elastica.field" alias="datetime" />
        </service>
        <service id="datasource.driver.elastica.field.entity" class="FSi\Component\DataSource\Driver\Elastica\Extension\Core\Field\Entity">
            <tag name="datasource.driver.elastica.field" alias="entity" />
        </service>
        <service id="datasource.driver.elastica.field.number" class="FSi\Component\DataSource\Driver\Elastica\Extension\Core\Field\Number">
            <tag name="datasource.driver.elastica.field" alias="number" />
        </service>
        <service id="datasource.driver.elastica.field.text" class="FSi\Component\DataSource\Driver\Elastica\Extension\Core\Field\Text">
            <tag name="datasource.driver.elastica.field" alias="text" />
        </service>
        <service id="datasource.driver.elastica.field.time" class="FSi\Component\DataSource\Driver\Elastica\Extension\Core\Field\Time">
            <tag name="datasource.driver.elastica.field" alias="time" />
        </service>
        <service id="datasource.driver.elastica.field.boolean" class="FSi\Component\DataSource\Driver\Elastica\Extension\Core\Field\Boolean">
            <tag name="datasource.driver.elastica.field" alias="boolean" />
        </service>

        <!-- OrderingExtension -->
        <service id="datasource.driver.elastica.subscriber.ordering" class="FSi\Component\DataSource\Driver\Elastica\Extension\Ordering\OrderingDriverExtension">
            <tag name="datasource.driver.elastica.subscriber" alias="ordering" />
        </service>
        <service id="datasource.driver.elastica.field.subscriber.ordering" class="FSi\Component\DataSource\Extension\Core\Ordering\Field\FieldExtension">
            <tag name="datasource.driver.elastica.field.subscriber" alias="ordering" />
        </service>

        <!-- Symfony/FormExtension -->
        <service id="datasource.driver.elastica.field.subscriber.symfonyform" class="FSi\Component\DataSource\Extension\Symfony\Form\Field\FormFieldExtension">
            <tag name="datasource.driver.elastica.field.subscriber" alias="symfonyform" />
            <argument type="service" id="form.factory" />
        </service>
        <service id="datasource.driver.elastica.field.subscriber.symfony_null_form" class="FSi\Bundle\DataSourceBundle\DataSource\Extension\Symfony\Form\Field\FormFieldExtension">
            <tag name="datasource.driver.elastica.field.subscriber" alias="symfony_null_form" />
            <argument type="service" id="translator" />
        </service>
    </services>
</container>
/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class FsiDemoExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $xmlLoader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $xmlLoader->load('elastica-driver.xml');
    }
}