germania-kg/permissions

2.1.5 2022-03-30 10:14 UTC

This package is auto-updated.

Last update: 2024-11-29 05:03:29 UTC


README

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation

$ composer require germania-kg/permissions

MySQL users may install the tables permissions and permissions_roles using install.sql.txt in sql/ directory.

Usage

<?php
use Germania\Permissions\PermissionsAcl;

// Have your PDO and optional a PSR-3 Logger at hand
$pdo    = new PDO;
$logger = new Monolog;

// Pass PDO and table names,
// optionally with PSR-3 Logger
$perms = new PermissionsAcl( $pdo, "permissions", "permissions_roles" );
$perms = new PermissionsAcl( $pdo, "permissions", "permissions_roles", $logger );

// Use Callable
$acl = $perms();
print_r( $acl );

// Keys are permissions;
// Element arrays are roles
(
    [bar] => Array
        (
            [0] => 1
        )

    [foo] => Array
        (
            [0] => 1
            [1] => 2
        )

    [quc] => Array
        (
        )

)

Development

$ git clone https://github.com/GermaniaKG/Permissions.git
$ cd Permissions
$ composer install

Setup MySQL tables permissions and permissions_roles as in sql/install.sql.txt.

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit

In phpunit.xml, edit the database credentials:

<php>
	<var name="DB_DSN"    value="mysql:host=localhost;dbname=test;charset=utf8" />
	<var name="DB_USER"   value="root" />
	<var name="DB_PASSWD" value="" />
	<var name="DB_DBNAME" value="test" />
	<var name="DB_SETUP"  value="sql/install.sql.txt" />
</php>

Go to project root and issue phpunit.