PHP code example of gbprod / elastica-specification
1. Go to this page and download the library: Download gbprod/elastica-specification library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gbprod / elastica-specification example snippets
namespace GBProd\Acme\Elastica\SpecificationFactory;
use GBProd\ElasticaSpecification\QueryFactory\Factory;
use GBProd\Specification\Specification;
use Elastica\QueryBuilder;
class IsAvailableFactory implements Factory
{
public function create(Specification $spec, QueryBuilder $qb)
{
return $qb->query()->bool()
->addMust(
$qb->query()->term(['available' => "0"]),
)
;
}
}
$registry = new GBProd\ElasticaSpecification\Registry();
$qb = new \Elastica\QueryBuilder();
$handler = new GBProd\ElasticaSpecification\Handler($registry, $qb);
$handler->registerFactory(IsAvailable::class, new IsAvailableFactory());
$handler->registerFactory(StockGreaterThan::class, new StockGreaterThanFactory());