2017 © Pedro Peláez
 

bundle elastica-specification-bundle

This bundle integrates elastica-specification with Symfony

image

gbprod/elastica-specification-bundle

This bundle integrates elastica-specification with Symfony

  • Thursday, February 22, 2018
  • by gbprod
  • Repository
  • 1 Watchers
  • 2 Stars
  • 7,533 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 9 % Grown

The README.md

Elastica specification bundle

This bundle integrates elastica-specification with Symfony., (*1)

Build Status codecov Scrutinizer Code Quality Dependency Status, (*2)

Latest Stable Version Total Downloads Latest Unstable Version License, (*3)

Installation

Download bundle using composer :, (*4)

composer require gbprod/elastica-specification-bundle

Declare in your app/AppKernel.php file:, (*5)

<?php
// app/AppKernel.php

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

Create your specification and your query factory

Take a look to Specification and Elastica Specification libraries for more informations., (*6)

Create a specification

<?php

namespace GBProd\Acme\CoreDomain\Specification\Product;

use GBProd\Specification\Specification;

class IsAvailable implements Specification
{
    public function isSatisfiedBy($candidate): bool
    {
        return $candidate->isSellable()
            && $candidate->expirationDate() > new \DateTime('now')
        ;
    }
}

Create a query factory

<?php

namespace GBProd\Acme\Infrastructure\Elastica\QueryFactory\Product;

use GBProd\ElasticaSpecification\QueryFactory\Factory;
use GBProd\Specification\Specification;
use Elastica\QueryBuilder;

class IsAvailableFactory implements Factory
{
    public function build(Specification $spec, QueryBuilder $qb)
    {
        return $qb->query()->bool()
            ->addMust()
                $qb->query()->term(['available' => "0"]),
            )
        ;
    }
}

Configuration

Declare your Factory

# src/GBProd/Acme/AcmeBundle/Resource/config/service.yml

services:
    acme.elastica.query_factory.is_available:
        class: GBProd\Acme\Infrastructure\Elastica\QueryFactory\Product\IsAvailableFactory
        tags:
            - { name: elastica.query_factory, specification: GBProd\Acme\CoreDomain\Specification\Product\IsAvailable }

Inject handler in your repository class

# src/GBProd/Acme/AcmeBundle/Resource/config/service.yml

services:
    acme.product_repository:
        class: GBProd\Acme\Infrastructure\Product\ElasticaProductRepository
        arguments:
            - "@elastica.client"
            - "@gbprod.elastica_specification_handler"
<?php

namespace GBProd\Acme\Infrastructure\Product;

use Elastica\Client;
use Elastica\QueryBuilder;
use GBProd\ElasticaSpecification\Handler;
use GBProd\Specification\Specification;

class ElasticaProductRepository implements ProductRepository
{
    private $client;

    private $handler;

    public function __construct(Client $em, Handler $handler)
    {
        $this->client  = $client;
        $this->handler = $handler;
    }

    public function findSatisfying(Specification $specification)
    {
        $type = $this
            ->getIndex('catalog')
            ->getType('product')
        ;

        $query = $this->handler->handle($specification, new QueryBuilder());

        return $type->search($query);
    }
}

Usage

<?php

$products = $productRepository->findSatisfying(
    new AndX(
        new IsAvailable(),
        new IsLowStock()
    )
);

Elastica configuration

You can specify the Elastica DSL version using dsl_version configuration node (default: Latest). To use a different version, just set it to the version classname., (*7)

# app/config/config.yml
elastica_specification_bundle:
    dsl_version: Version120 

The Versions

22/02 2018

dev-master

9999999-dev

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT WTFPL

The Requires

 

The Development Requires

by Gilles

22/02 2018

dev-chore/licence

dev-chore/licence

This bundle integrates elastica-specification with Symfony

  Sources   Download

WTFPL

The Requires

 

The Development Requires

by Gilles

08/02 2018

v2.1.0

2.1.0.0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

01/02 2018

dev-feat/es6-sf4

dev-feat/es6-sf4

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

27/06 2017

v2.0.0

2.0.0.0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

26/06 2017

v1.1.x-dev

1.1.9999999.9999999-dev

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

26/06 2017

v1.1.0

1.1.0.0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

01/01 2017

v1.0.0

1.0.0.0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

29/12 2016

v1.0-beta.0

1.0.0.0-beta0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

12/09 2016

v0.2.0

0.2.0.0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

05/09 2016

v0.1.0

0.1.0.0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

05/09 2016

V0.1-alpha.0

0.1.0.0-alpha0

This bundle integrates elastica-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles