-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from xiaocaigua/master
add readme
- Loading branch information
Showing
5 changed files
with
113 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
composer.lock | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: mayn | ||
* Date: 2019/7/3 | ||
* Time: 21:06 | ||
*/ | ||
require_once "vendor/autoload.php"; | ||
|
||
use EasySwoole\Policy\Policy; | ||
use EasySwoole\Policy\PolicyNode; | ||
|
||
//$policy = new Policy(); | ||
// | ||
////添加节点权限 | ||
//$policy->addPath('/user/add', PolicyNode::EFFECT_ALLOW); //添加允许的单节点 | ||
//$policy->addPath('/user/update', PolicyNode::EFFECT_ALLOW); | ||
//$policy->addPath('/user/delete', PolicyNode::EFFECT_DENY); //添加拒绝的单节点 | ||
//$policy->addPath('/user/*', PolicyNode::EFFECT_DENY); //添加拒绝的通配节点 | ||
// | ||
////验证权限 | ||
//var_dump($policy->check('user/asdasd/dsad')); //deny | ||
//var_dump($policy->check('user/add')); //allow | ||
//var_dump($policy->check('user/update')); //allow | ||
//var_dump($policy->check('user/delete')); //deny | ||
// | ||
//print_r($policy->toArray());//树形结构 | ||
|
||
|
||
//对象添加授权 | ||
$root = new PolicyNode('*'); | ||
|
||
$userChild = $root->addChild('user'); | ||
$userAddChild = $userChild->addChild('add'); | ||
$userAddChild->addChild('aaaaaa')->setAllow(PolicyNode::EFFECT_ALLOW); | ||
$userChild->addChild('update')->setAllow(PolicyNode::EFFECT_DENY); | ||
$userChild->addChild('*')->setAllow(PolicyNode::EFFECT_ALLOW); | ||
|
||
$apiChild = $root->addChild('charge'); | ||
$apiChild->addChild('*'); | ||
|
||
$node = $root->search('/user/add/aaaa'); | ||
if ($node) { | ||
var_dump($node->isAllow()); | ||
} |