I would need different application rules for different users. For example I would need to have a rule, what checks that the user can not save an article in the past. However I would let admins to do this.
I have like 6 different rules, and I do not want to copy-paste the same check to all of them.
Instead of Copy/Pasting you can make standalone Rules objects that decorate other rules apply their rules based on the state in the entities/relations that are being persisted.
class AdminAllowedRule
{
public function __construct($callable)
{
$this->callable = $callable;
}
public function __invoke(EntityInterface $entity, $options)
{
if ($entity->user->is_admin) {
return true;
}
$cb = $this->callable;
return $cb($entity, $options);
}
}
This decorator approach would allow you do decorate your rules with the ‘admin allowed’ logic.