Giter Site home page Giter Site logo

php-casbin / zend-db-adapter Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 1.0 15 KB

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

License: Apache License 2.0

PHP 100.00%
casbin zend-db zend-framework access-control authorization database permissions

zend-db-adapter's Introduction

Zend Db Adapter for PHP-Casbin

Build Status Coverage Status Latest Stable Version Total Downloads License

Repository abandoned 2020-05-25

This repository has moved to php-casbin/laminas-db-adapter.

Zend-Db adapter for PHP-Casbin.

The list of officially supported drivers:

  • IbmDb2: The ext/ibm_db2 driver
  • Mysqli: The ext/mysqli driver
  • Oci8: The ext/oci8 driver
  • Pgsql: The ext/pgsql driver
  • Sqlsrv: The ext/sqlsrv driver (from Microsoft)
  • Pdo_Mysql: MySQL via the PDO extension
  • Pdo_Sqlite: SQLite via the PDO extension
  • Pdo_Pgsql: PostgreSQL via the PDO extension

Installation

Use Composer.

composer require casbin/zend-db-adapter

Usage

Before using it, you need to create a table named casbin_rule for Casbin to store the policy.

Take mysql as an example:

CREATE TABLE `casbin_rule` (
  `ptype` varchar(255) NOT NULL,
  `v0` varchar(255) DEFAULT NULL,
  `v1` varchar(255) DEFAULT NULL,
  `v2` varchar(255) DEFAULT NULL,
  `v3` varchar(255) DEFAULT NULL,
  `v4` varchar(255) DEFAULT NULL,
  `v5` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Then you can start like this:

require_once './vendor/autoload.php';

use Casbin\Enforcer;
use Casbin\Util\Log;
use CasbinAdapter\ZendDb\Adapter;

$adapter = new Adapter([
	'driver' => 'Pdo_Mysql', // IbmDb2, Mysqli, Oci8, Pgsql, Sqlsrv, Pdo_Mysql, Pdo_Sqlite, Pdo_Pgsql
	'hostname' => '127.0.0.1',
	'database' => 'test',
	'username' => 'root',
	'password' => '',
	'port' => '3306',
]);

$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.

zend-db-adapter's People

Contributors

leeqvip avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

leeqvip

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.