1. Go to this page and download the library: Download casbin/webman-permission library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
casbin / webman-permission example snippets
$builder = new \DI\ContainerBuilder();
$builder->addDefinitions(config('dependence', []));
$builder->useAutowiring(true);
return $builder->build();
use Casbin\WebmanPermission\Permission;
// adds permissions to a user
Permission::addPermissionForUser('eve', 'articles', 'read');
// adds a role for a user.
Permission::addRoleForUser('eve', 'writer');
// adds permissions to a rule
Permission::addPolicy('writer', 'articles','edit');
$permission = \Casbin\WebmanPermission\Permission::driver('restful_conf');
// adds permissions to a user
$permission->addPermissionForUser('eve', 'articles', 'read');
// adds a role for a user.
$permission->addRoleForUser('eve', 'writer');
// adds permissions to a rule
$permission->addPolicy('writer', 'articles','edit');
if ($permission->enforce('eve', 'articles', 'edit')) {
echo '恭喜你!通过权限认证';
} else {
echo '对不起,您没有该资源访问权限';
}
if (is_null(static::$_manager)) {
static::$_manager = new Enforcer($model, Container::get($config['adapter']),false);
}
if (is_null(static::$_manager)) {
if ($config['adapter'] == DatabaseAdapter::class) {
$_model = new RuleModel();
} elseif ($config['adapter'] == LaravelDatabaseAdapter::class) {
$_model = new LaravelRuleModel();
}
static::$_manager = new Enforcer($model, new $config['adapter']($_model), false);
}
php start.php restart
php start.php restart -d
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.