Uses Symfony-like voters to check permissions
Install:
composer require onix-systems-php/hyperf-policy
To make it works, you need:
-
create policy class based on
OnixSystemsPHP\HyperfPolicy\Policy\AbstractPolicy
-
add
OnixSystemsPHP\HyperfPolicy\Annotation\Policy
annotation to the policy and setup it's priority (higher number executes first) -
specify what classes\objects and actions your policy will work with
-
specify vote logic and return one of the values:
PolicyVote::ACCESS_DENIED
- stop execution and throw exception specified ingetException
methodPolicyVote::ACCESS_GRANTED
- allow current action and skip all following policiesPolicyVote::ACCESS_ABSTAIN
- go to next policy, allow action if no policies left to check
-
create data specifier class based on
OnixSystemsPHP\HyperfPolicy\Policy\AbstractDataSpecifier
-
add
OnixSystemsPHP\HyperfPolicy\Annotation\DataSpecifier
annotation to the specifier and setup it's priority (higher number executes first) -
specify what repositories and actions your specifier will work with