PHP code example of sinevia / php-library-business-rule
1. Go to this page and download the library: Download sinevia/php-library-business-rule 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/ */
sinevia / php-library-business-rule example snippets
$rule = (new BusinessRule())->context([])->condition(function($context){ return true; });
if ($rule->fails()) {
// Execute fail logic
}
if ($rule->passes()) {
// Execute pass logic
}
// 1. Specify the business rule class
class AllowAccessRule extends BusinessRule {
function __construct() {
$this->condition(function($context){
return ($context['user']->isEmailConfirmed() AND $context['user']->isActive());
});
}
}
// Use the shortcut init function with the context to initialize the rule
if (AllowAccessRule::init(['user'=>$user)->fails()) {
die('You are not allowed access to this part of the website');
}