php - Using fnmatch() to test for permissions in level1.level2.level3 -
i looking re-working permissions system in php built while ago. current version has exact permissions admin have following permissions:
acl.manage.self acl.manage.others
that user has access manage own permissions, as-well others.
however while working on new applications, attempted tap current permissions system giving myself access entire application via:
lst.*
that way don't have give myself bunch .view
.manage
etc.
it seems though existing system not understand * wildcard. sitting here trying re-write "has_permission"
so current working test environment have created user following permissions:
array(3) { [0]=> string(1) "*" [1]=> string(15) "fake.permission" [2]=> string(27) "none.of.these.should.matter" }
technically permission matters [0] says should have permission , want.
i @ loss how implement flow method:
function has_perm($perm){ //if checking if have perm 'acl.manage.all' //this function should return true if have of following: // *, acl.*, acl.manage.*, acl.manage.all //exact check foreach($this->perms $p){ if($p===$perm){ return true; } } }
any nudge in right direction awesome.
your current code returns true if needed permission $perm
matches of permissions $p
.
you need change return true if needed permission $perm
matches of fnmatch()
patterns $p
.
try this:
foreach($this->perms $p) { if (fnmatch($p, $perm)) { return true; } }
you don't need keep exact match check, because fnmatch()
still detect exact matches if permissions don't contain wildcards.
Comments
Post a Comment