rulerz-php / doctrine-dbal
Doctrine DBAL compilation target for RulerZ
Installs: 3 396
Dependents: 0
Suggesters: 5
Security: 0
Stars: 5
Watchers: 2
Forks: 6
Open Issues: 0
Requires
- php: >=7.1
- doctrine/dbal: ^2.4
- kphoen/rulerz: dev-master as 1.0.0
Requires (Dev)
- behat/behat: ~3.0
- kphoen/rusty: dev-master
- liip/rmt: ^1.2
- phpunit/phpunit: ^7.1
This package is auto-updated.
Last update: 2024-10-29 05:10:55 UTC
README
Doctrine DBAL compilation target for RulerZ.
Usage
Doctrine DBAL is one of the targets supported by RulerZ.
This cookbook will show you how to retrieve records using Doctrine DBAL and RulerZ.
Here is a summary of what you will have to do:
Configure Doctrine DBAL
This subject won't be directly treated here. You can either follow the official documentation or use a bundle/module/whatever the framework you're using promotes.
Configure RulerZ
Once Doctrine DBAL is installed and configured we can the RulerZ engine:
$rulerz = new RulerZ( $compiler, [ new \RulerZ\DoctrineDBAL\Target\DoctrineDBAL(), // this line is Doctrine DBAL-specific // other compilation targets... ] );
The only Doctrine DBAL-related configuration is the DoctrineDBAL
target being added to the list
of the known compilation targets.
Filter your target
Now that both the DBAL and RulerZ are ready, you can use them to retrieve data.
The DoctrineDBAL
instance that we previously injected into the RulerZ engine
only knows how to use Doctrine\DBAL\Query\QueryBuilder
so the first step
is to create one and configure it:
$connection = DriverManager::getConnection([/** connection parameters */]); $queryBuilder = $connection->createQueryBuilder(); $queryBuilder ->select('pseudo', 'gender', 'points') ->from('players');
And as usual, we call RulerZ with our target (the QueryBuilder
object) and our rule.
RulerZ will build the right executor for the given target and use it to filter
the data, or in our case to retrieve data from a database.
$rule = 'gender = :gender and points > :points'; $parameters = [ 'points' => 30, 'gender' => 'M', ]; var_dump( iterator_to_array($rulerz->filter($queryBuilder, $rule, $parameters)) );
That's it!
License
This library is under the MIT license.