Giter Site home page Giter Site logo

php-casbin / dbal-adapter Goto Github PK

View Code? Open in Web Editor NEW
10.0 5.0 4.0 25 KB

Doctrine DBAL Adapter for Casbin, Casbin is a powerful and efficient open-source access control library.

License: Apache License 2.0

PHP 100.00%
casbin rbac permission acl adapter dbal database

dbal-adapter's Introduction

Doctrine DBAL Adapter for Casbin

Build Status Coverage Status Latest Stable Version Total Downloads License

Doctrine DBAL Adapter for PHP-Casbin, Casbin is a powerful and efficient open-source access control library.

The following database vendors are currently supported:

  • MySQL
  • Oracle
  • Microsoft SQL Server
  • PostgreSQL
  • SAP Sybase SQL Anywhere
  • SQLite
  • Drizzle

Installation

Via Composer.

composer require casbin/dbal-adapter

Usage

require_once './vendor/autoload.php';

use Casbin\Enforcer;
use CasbinAdapter\DBAL\Adapter as DatabaseAdapter;

$config = [
    // Either 'driver' with one of the following values:
    // pdo_mysql,pdo_sqlite,pdo_pgsql,pdo_oci (unstable),pdo_sqlsrv,pdo_sqlsrv,
    // mysqli,sqlanywhere,sqlsrv,ibm_db2 (unstable),drizzle_pdo_mysql
    'driver' => 'pdo_mysql',
    'host' => '127.0.0.1',
    'dbname' => 'test',
    'user' => 'root',
    'password' => '',
    'port' => '3306',
];

$adapter = DatabaseAdapter::newAdapter($config);

$e = new Enforcer('path/to/model.conf', $adapter);

$sub = "alice"; // the user that wants to access a resource.
$obj = "data1"; // the resource that is going to be accessed.
$act = "read"; // the operation that the user performs on the resource.

if ($e->enforce($sub, $obj, $act) === true) {
    // permit alice to read data1
} else {
    // deny the request, show an error
}

Getting Help

License

This project is licensed under the Apache 2.0 license.

dbal-adapter's People

Contributors

basakest avatar leeqvip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dbal-adapter's Issues

Error loading policy during instantiation

I get this error when trying to instantiate the Enforcer class using this adapter:

TypeError:
Argument 1 passed to CasbinAdapter\DBAL\Adapter::fetch() must be an instance of Doctrine\DBAL\Result, instance of Doctrine\DBAL\Driver\PDOStatement given, called in /<redacted>/vendor/casbin/dbal-adapter/src/Adapter.php on line 153

  at /<redacted>/vendor/casbin/dbal-adapter/src/Adapter.php:495
  at CasbinAdapter\DBAL\Adapter->fetch(object(PDOStatement))
     (/<redacted>/vendor/casbin/dbal-adapter/src/Adapter.php:153)
  at CasbinAdapter\DBAL\Adapter->loadPolicy(object(Model))
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:363)
  at Casbin\CoreEnforcer->loadPolicy()
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:223)
  at Casbin\CoreEnforcer->initWithModelAndAdapter(object(Model), object(Adapter))
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:198)
  at Casbin\CoreEnforcer->initWithAdapter('/<redacted>/permission_model.conf', object(Adapter))
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:150)
  at Casbin\CoreEnforcer->__construct('/<redacted>/resources/permission_model.conf', object(Adapter))
     (/<redacted>/src/Utilities/Permission.php:52)

From the composer.json file in this library, Doctrine 2.9 and 3.0 are supported. I am using Doctrine 2.9.3.

Digging through the source code, it looks like the execute method from DBAL Query Builder (called on line 151 in Adapter.php) returns a ResultStatement rather than the expected Result object.

Passing an array of parameters instead of a Connection object in the constructor produces the same result. Am I doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.