fivelab / ruler
Add rule for satisfy objects and generate queries based on specifications.
Installs: 9 856
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ~7.4 || ~8.0
Requires (Dev)
- doctrine/annotations: ~1.10
- doctrine/orm: ~2.6
- escapestudios/symfony2-coding-standard: ~3.12.0
- phpmetrics/phpmetrics: ~2.8
- phpstan/phpstan: ~1.9.2
- phpunit/phpunit: ~9.5
- ruflin/elastica: ~7.0
This package is auto-updated.
Last update: 2024-11-15 21:54:23 UTC
README
#StandWithUkraineRuler
The library for apply the string rule to any query builders (Doctrine ORM, Elastica, etc...).
For start use ruler, you should create the target factories for all supported targets for you. After, you can create ruler and apply any rules:
<?php use FiveLab\Component\Ruler\Ruler; use FiveLab\Component\Ruler\Target\Targets; use FiveLab\Component\Ruler\Target\DoctrineOrmTarget; use FiveLab\Component\Ruler\Target\ElasticaTarget; $targets = new Targets( new DoctrineOrmTarget(), new ElasticaTarget() ); $ruler = new Ruler($targets); // Apply rules $qb = $entityManager->createQueryBuilder() ->from('Product', 'products') ->select('products'); $ruler->apply($qb, 'category.key in (:categories) and enabled = :enabled and price > :price', [ 'categories' => ['cat1', 'cat2'], 'enabled' => true, 'price' => 100 ]);
Note: system auto-detect joins based on dot (
.
) for SQL targets and nested for document targets. If column contain dot (in ES as an example), you can escape dot via\
(money\.amount
).
Development
For easy development you can use the Docker
.
$ docker build -t ruler . $ docker run -it -v $(pwd):/code --name ruler ruler bash
After success run and attach to container you must install vendors:
$ composer update
Before create the PR or merge into develop, please run next commands for validate code:
$ ./bin/phpunit $ ./bin/phpcs --config-set show_warnings 0 $ ./bin/phpcs --standard=vendor/escapestudios/symfony2-coding-standard/Symfony/ src/ $ ./bin/phpcs --standard=tests/phpcs-ruleset.xml tests/