germania-kg/user-roles

1.2.1 2022-03-30 10:11 UTC

This package is auto-updated.

Last update: 2024-04-29 03:32:35 UTC


README

This package is distilled from legacy code. You certainly will not want to use this your production code.

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

Installation

Setup MySQL database with table creation listing in sql/users_roles.sql.txt. Use Composer for PHP:

$ composer require germania-kg/user-roles

Assign a user ID to a single role ID:

<?php
use Germania\UserRoles\PdoAssignUserToRole;

$pdo    = new PDO( ... );
$logger = new Monolog();
// Default, thus optional
$table  = 'users_roles_mm';

$assigner = new PdoAssignUserToRole( $pdo, $logger, $table);

$user_id = 42;
$assigner( $user_id, 1);   // e.g. Admins
$assigner( $user_id, 2);   // e.g. Co-workers
$assigner( $user_id, 10);  // e.g. Sales people

Retrieve user's role IDs

Retrieve an array containing role IDs for the given user.

<?php
use Germania\UserRoles\PdoUserRoles;

$pdo     = new PDO( ... );
// Default, thus optional
$table   = 'users_roles_mm';

$roles_finder = new PdoUserRoles( $pdo, $table);

$user_id = 42;
$roles_array = $roles_finder( $user_id );

Issues

  • user_id column name in SQL still is client_id. This is legacy and subject to change in upcoming major versions. Discuss at issue #1.

Also see full issues list.

Development

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

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