-
Notifications
You must be signed in to change notification settings - Fork 111
Added ability to set multiple assertions and their condition for permissions #320
base: master
Are you sure you want to change the base?
Changes from 4 commits
7d5795e
9b5d507
01e35ba
b06275f
0a3e9a7
d2a7e27
8c6a9c3
311b942
d9a86ad
1a30f06
c695e41
47e17f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,5 @@ public function assert(AuthorizationService $authorizationService, $context = nu | |
|
||
return false; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,17 +81,17 @@ public function setAssertion($permission, $assertion) | |
// if is name of the assertion, retrieve an actual instance from assertion plugin manager | ||
if (is_string($assertion)) { | ||
$assertion = $this->assertionPluginManager->get($assertion); | ||
} else if (is_array($assertion)) { // else if multiple assertion definition, create assertion set. | ||
} elseif (is_array($assertion)) { // else if multiple assertion definition, create assertion set. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this whole block here? can't we move it to AssertionSet? something like: if (is_array($assertion)) {
$assertion = new AssertionSet($assertion, $this->assertionPluginManager);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one more thought. Maybe when moved to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I like moving the retrieval of assertions to AssertionSet class. Main idea behind the AssertionSet is to be a somewhat simple reusable container for assertions and specifically to have the ability to specify the condition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand your concern, but look at the contradicting response/suggestion from bakura10 few months ago... this was the initial reasoning behind adding it and I am very fond of it since then. In fact I am using the concept now on several projects (on tweaked ZfcRbac module) and I like the versatility of that solution. But I am opened to suggestions of course. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry but I don't understand I just say this block is almost same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the following approach?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danizord maybe, but not sure I like it :) also have concerns about performance. |
||
|
||
// move assertion definition under a key 'assertions'. | ||
if (!isset($assertion['assertions'])) { | ||
$assertion['assertions'] = (array)$assertion; | ||
} else if (!is_array($assertion['assertions'])) { | ||
} elseif (!is_array($assertion['assertions'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove else, should be: if (!is_array($assertion['assertions'])) { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove else, this should be: if (!is_array($assertion['assertions'])) { |
||
$assertion['assertions'] = (array)$assertion['assertions']; | ||
} | ||
|
||
// retrieve an actual instance from assertion plugin manager if necessary | ||
foreach ($assertion['assertions'] as $key=>$value) { | ||
foreach ($assertion['assertions'] as $key => $value) { | ||
if (is_string($value)) { | ||
$assertion['assertions'][$key] = $this->assertionPluginManager->get($value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fetching assertions would be better when they are really needed in |
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's slower to do it here instead of where it was in
assert()
method because it will be created on every request even if this is not used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, point. Will move it to assert method.