PHP code example of hoathis / symfony-ruler-bundle
1. Go to this page and download the library: Download hoathis/symfony-ruler-bundle 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/ */
hoathis / symfony-ruler-bundle example snippets
// app/AppKernel.php
class AppKernel extends Kernel
{
// …
public function registerBundles()
{
$bundles = array(
// …
new Hoathis\SymfonyRulerBundle\HoathisSymfonyRulerBundle(),
);
// …
}
}
public function indexAction(Request $request)
{
// 1. Write a rule.
$ruler = $this->get('hoathis.ruler');
$rule = 'group in ["customer", "guest"] and points > 30';
// 2. Create a context.
$context = $ruler->getNewContext();
$context['group'] = 'customer';
$context['points'] = function () {
return 42;
};
// 3. Assert!
var_dump(
$ruler->assert($rule, $context) // bool(true)
);
}