germania-kg / user-roles
1.2.1
2022-03-30 10:11 UTC
Requires
- php: ^5.6|^7.0
- psr/container: ^1.0
- psr/log: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.7|^6.0
- pimple/pimple: ^3.2
Suggests
- pimple/pimple: This package provides a Pimple ServiceProvider
README
This package is distilled from legacy code. You certainly will not want to use this your production code.
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