Download the PHP package jsalam/ugrpm without Composer
On this page you can find all versions of the php package jsalam/ugrpm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package ugrpm
Short Description Manage users and groups roles and permessions
License MIT
Homepage https://aljehni.com/libraries/ugrpm
Informations about the package ugrpm
UGRPM
A simple and easy to use PHP object oriented library to manage (Users,Groups,Roles).
This library use MySql database and PDO Object to connect.
It's work with user as his id and don't care what the table you had made or its columns.
You must have a database connection and pass it as PDO connection object to the UGRPM constructor.
Built by Salam Aljehni (https://aljehni.github.io)
Library home: (https://aljehni.github.io/ugrpm/)
Github link (https://github.com/salamj/ugrpm)
Installation
- Import tables from sql directory to your database
-
Add UGRPM to composer.json then update.
- Add namespace where you want to use UGRPM, Group or Role classes only what you need.
OR
If you would use try ... catch you must use exceptions classes.
Exceptions using will be discuss below.
Usage
- First, you must create a new instance of UGRPM class by passing your PDO connection object.
Suppose you create PDO object like this:
Then, create UGRPM object:
Roles
Create Role
Role class constructor accept two parameters, id
and role
, to create a new Role instance use:
Default value to id
is 0
and ""
to role.
If Role not exists in the database and you want to create one do not pass id
.
After that you can work with $role
object by it's methods:
Work With Roles
Insert role to database, retrieve role(s) by (id,role,class,method,class and method) ,get all roles and remove role.
Groups
UGRPM enable you to create groups with (id,name,description) properties, then, you may work with them like add role to groups , add users to group, update groups ...
Create Group
Group class constructor accept three parameters, id
and groupName
, description
, to create a new Group instance use:
Default value to id
is 0
and ""
to groupName
and description
.
If group not exists in the database and you want to create one do not pass id
.
After that you can work with $group
object by it's methods:
Work With Groups
Insert group to database, retrieve group(s) by (id
,groupName
) ,get all groups and remove group.
Group Roles
In this section you will learn how to work with (Role-Group) methods. We will make example contains groups and roles and make relations between them.
User Roles
Like (Group-Roles) we can add ,retrieve and remove roles to users or users to roles. Without many examples, these are the methods you can use:
User Group
Since users may belongs to groups, we can add user(s) to group(s) and retrieve group's users or user's group , and removing in the way.
These method are available to use.
There are Role several exceptions to use, namespaces for them are:
Exceptions
- Group Exceptions
- Role Exceptions
- Group Role Exceptions
- User Group Exceptions
- User Role Exceptions
Group Exceptions
Jsalam\UGRPM\Exceptions\GroupExceptions\DuplicatedGroupException
Catched when trying to create a group with a name that already existing.
Jsalam\UGRPM\Exceptions\GroupExceptions\GroupNotFoundException
Catched when trying to get group that's not found in database using getGroupById
or getGroupByGroupName
.
Jsalam\UGRPM\Exceptions\GroupExceptions\GroupTypeException
Catched when passing array of groups that contain item with invalid Group Object
or Integer value (group id).
Like createRoleGroups($role,[ARRAY_OF_GROUPS
]).
Role Exceptions
Jsalam\UGRPM\Exceptions\RoleExceptions\DuplicatedRoleException
Catched when create a role with role
property that already exists in database using createRole()
method.
-
Jsalam\UGRPM\Exceptions\RoleExceptions\InvalidRoleClassNameException
Catched when create new Role(role:
classNamespace
@method) with invalid role class, that class must be a valid namespace likeApps\Content
or\Apps\Content\Article
... Jsalam\UGRPM\Exceptions\RoleExceptions\RoleNameException
Catched when create a role with role
invalid property, role
must be classNamespace
then @
then method name
.
Jsalam\UGRPM\Exceptions\RoleExceptions\RoleNotFoundException
Catched when trying to get role that's not found in database using getRoleById
or getRolesByClass
...
Jsalam\UGRPM\Exceptions\RoleExceptions\RoleTypeException
'
Catched when passing array of roles that contain item with invalid Role Object
or Integer value (role id).
Like createGroupRoles($group,[ARRAY_OF_ROLES
])
Group Role Exceptions
Jsalam\UGRPM\Exceptions\GroupRoleExceptions\GroupAlreadyHasRoleException
Catched when trying to add role(s) to group(s) that already have that role(s).
User Group Exceptions
Jsalam\UGRPM\Exceptions\UserGroupExceptions\UserAlreadyInGroupException
Catched when trying to add user(s) to group(s) where already in that group role(s).
User Role Exceptions
Jsalam\UGRPM\Exceptions\UserRoleExceptions\UserAlreadyHasRoleException
Catched when trying to add role(s) to user(s) where already have that role(s).
Credit
Salam Aljehni, salam[at]gmail.com, link: (aljehni.github.io)[https://aljehni.github.io]