I think it would be useful to have possibility for defining assertions in this way, as those can be very easily persisted or serialized in contrast to CallbackAssertion for example. Also, having such dynamic and generic type of assertion is much more convenient when it comes to creating some permissions CRUD functionality.
Example usage
ExpressionAssertion::fromArray([
'left' => [ExpressionAssertion::OPERAND_CONTEXT_PROPERTY => 'role.username'],
'operator' => '=',
'right' => 'test',
]);
ExpressionAssertion::fromArray([
'left' => [ExpressionAssertion::OPERAND_CONTEXT_PROPERTY => 'role.age'],
'operator' => '>',
'right' => 20,
]);
ExpressionAssertion::fromArray([
'left' => [ExpressionAssertion::OPERAND_CONTEXT_PROPERTY => 'role.adult'], //resolves to isAdult() or getAdult() method on Role object
'operator' => '=',
'right' => true,
]);
ExpressionAssertion::fromArray([
'left' => [ExpressionAssertion::OPERAND_CONTEXT_PROPERTY => 'resource.short_description'], //resolves to either getShortDescription() method or short_description property
'operator' => 'regex',
'right' => '/ipsum/',
]);
I think it would be useful to have possibility for defining assertions in this way, as those can be very easily persisted or serialized in contrast to
CallbackAssertion
for example. Also, having such dynamic and generic type of assertion is much more convenient when it comes to creating some permissions CRUD functionality.Example usage