vgrdominik/elasticsearchhttpfoundation-bundle

Elasticsearch session storage management for Symfony2 applications.

v0.1.2 2014-07-05 21:40 UTC

README

About

This bundle provides easy elasticsearch session storage management for Symfony2.

Installation

To install this bundle, you'll need PHP >= 5.3, Symfony >= 2.4 and VGRElasticsearchBundle.

Step 1: Download VGRElasticsearchHttpFoundationBundle using composer

Tell composer to require VGRElasticsearchHttpFoundationBundle by running the command:

$ php composer.phar require "vgrdominik/elasticsearchhttpfoundation-bundle:dev-master"

Step 2: Enable the bundles

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        new VGR\ElasticsearchHttpFoundationBundle\VGRElasticsearchHttpFoundationBundle()
    );
}

Configuration

Elasticsearch config parameters:

# app/config/config.yml
framework:
    session:
        storage_id: vgr_elasticsearch_http_foundation.session.storage.elasticsearch_session_storage
        handler_id: vgr_elasticsearch_http_foundation.session.storage.handler.elasticsearch_session_handler

Create command to generate elasticsearch configuration

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use VGR\ElasticsearchHttpFoundationBundle\Entity\Session;

class CreateModelCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('my_app:model:create')
            ->setDescription('Create model')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $esm = $this->getContainer()->get('vgr.elasticsearch.manager.elasticsearch');

        $output->writeln('Creating index "'.Session::getIndex().'".');
        $esm->createIndex(Session::getIndex());
        $output->writeln('Index "'.Session::getIndex().'" created.');
        $output->writeln('Creating mapping "'.Session::getPath().'".');
        $esm->createMapping(Session::getIndex(), Session::getType(),  Session::getStructure());
        $output->writeln('Mapping "'.Session::getPath().'" created.');
    }
}