2017 © Pedro Peláez
 

bundle algolia-specification-bundle

This bundle integrates algolia-specification with Symfony

image

gbprod/algolia-specification-bundle

This bundle integrates algolia-specification with Symfony

  • Monday, February 26, 2018
  • by gbprod
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6,893 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 9 Versions
  • 9 % Grown

The README.md

Algolia specification bundle

This bundle integrates algolia-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/algolia-specification-bundle

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

<?php
// app/AppKernel.php

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

Create your specification and your query factory

Take a look to Specification and Algolia 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)
    {
        return $candidate->isSellable()
            && $candidate->expirationDate() > new \DateTime('now')
        ;
    }
}

Create a query factory

<?php

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

use GBProd\AlgoliaSpecification\QueryFactory\Factory;
use GBProd\Specification\Specification;
use Algolia\QueryBuilder;

class IsAvailableFactory implements Factory
{
    public function create(Specification $spec)
    {
        return 'available=1';
    }
}

Configuration

Declare your Factory

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

services:
    acme.algolia.query_factory.is_available:
        class: GBProd\Acme\Infrastructure\Algolia\QueryFactory\Product\IsAvailableFactory
        tags:
            - { name: algolia.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\AlgoliaProductRepository
        arguments:
            - "@algolia.client"
            - "@gbprod.algolia_specification_handler"
<?php

namespace GBProd\Acme\Infrastructure\Product;

use Algolia\Client;
use GBProd\AlgoliaSpecification\Handler;
use GBProd\Specification\Specification;

class AlgoliaProductRepository implements ProductRepository
{
    private $client;

    private $handler;

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

    public function findSatisfying(Specification $specification)
    {
        $index = $this->client->initIndex('products');

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

        return $type->search(['filters' => $query]);
    }
}

Usage

<?php

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

The Versions

26/02 2018

dev-master

9999999-dev

This bundle integrates algolia-specification with Symfony

  Sources   Download

MIT WTFPL

The Requires

 

The Development Requires

by Gilles

26/02 2018

v2.1.0

2.1.0.0

This bundle integrates algolia-specification with Symfony

  Sources   Download

WTFPL

The Requires

 

The Development Requires

by Gilles

22/02 2018

dev-chore/update-deps

dev-chore/update-deps

This bundle integrates algolia-specification with Symfony

  Sources   Download

WTFPL

The Requires

 

The Development Requires

by Gilles

29/06 2017

v2.0.0

2.0.0.0

This bundle integrates algolia-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

29/06 2017

dev-feat/v2

dev-feat/v2

This bundle integrates algolia-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

29/06 2017

v1.0.1

1.0.1.0

This bundle integrates algolia-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

29/06 2017

dev-fix/doc

dev-fix/doc

This bundle integrates algolia-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

29/06 2017

v1.0.0

1.0.0.0

This bundle integrates algolia-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles

12/09 2016

v0.0.1

0.0.1.0

This bundle integrates algolia-specification with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gilles