zendframework / zend-permissions-acl

BSD 3-Clause "New" or "Revised" License
60 stars 23 forks source link

Expression assertion #23

Closed nikolaposa closed 6 years ago

nikolaposa commented 8 years ago

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/',
]);
weierophinney commented 6 years ago

I've incorporated all feedback in #36; I would have pushed to your branch, but you've locked it. :smile:

michalbundyra commented 6 years ago

@weierophinney It can be closed now, as #36 is merged and 2.7.0 is released.