Use Casbin in Symfony Framework, Casbin is a powerful and efficient open-source access control library. Built on top of php-casbin/php-casbin and php-casbin/database-adapter
composer require videni/casbin:"^1.0@dev"
videni_casbin:
default_enforcer: mysql
enforcers:
mysql:
path: "%kernel.project_dir%/config/packages/videni_casbin/rbac_with_domains_model.conf"
adapter: mysql
adapters:
mysql:
class: Videni\Casbin\Adapter\DatabaseAdapter
options:
type: "mysql"
hostname: "db"
database: "zaizai"
username: "zaizai"
password: "zaizai"
hostport: "3306"
bin/console videni-casbin:install mysql
the mysql
is your adapter name
you can get the default enforcer by videni_casbin.default_enforcer
, others are managed by EnforcerManager.
/** @var \Videni\Casbin\EnforcerManager $enforcerManager **/
$enforcerManager->getEnforer('mysql'); // return the default enforcer if no argument provided.
A Symfony security voter which uses the default casbin enforcer.