Download the PHP package mr-luke/privileges without Composer

On this page you can find all versions of the php package mr-luke/privileges. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package privileges

Privileges Manager - Laravel multi-roles manager Package.

Latest Stable Version License Scrutinizer Code Quality Build Status

This package provides privileges manager that supports multi-roles, permissions and restrictions.

Getting Started

Privileges Manager has been developed using Laravel 5.5 It's recommended to test it out before using with previous versions. PHP >= 7.1.3 is required.

Note! This package is still in Beta release.

Installation

To install through composer, simply put the following in your composer.json file and run composer update

Or use the following command

Next, add the service provider to app/config/app.php

Note: Package is auto-discoverable!

Configuration

To use Privileges you need to setup your Authorizable model & allowed scopes in config file:

You can also set a mapping rule that transform a given Eloquent model reference to a scope:

By default Detector returns bool value in case of allowed or denied access but you can set a custom on:

You can also publish config file via command:

Usage

Facade

You can access to Manager and Detector using Mrluke\Privileges\Facades namespace.

Contracts

Privileges is a packages built with Contracts. You need to implement Mrluke\Privileges\Contracts\Authorizable to your User model first. It is recommended to use default Mrluke\Privilges\Extentions\Authorizable trait combined with Contract:

Manager - Mrluke\Privileges\Manager

Manager is a main tool that provides a simple interface to assign Role & Privileges to Authorizable.

Allows you to assign new Mrluke\Privileges\Models\Role to Authorizable. $role can be one of three values: int in case you know Role id, Role instance or array<int> in case you want to assign more roles at once.

Returns permission level for given Authorizable based on roles & personal permissions in a $scope. Note! Personal permissions are always on top.

Returns array of restrictions in given $scope like: IP or Time restrictions for a given Authorizable.

Using this method you can get a scope that is connected with Model by mapping, eg: \App\User::class => 'users'.

Returns Mrluke\Privileges\Models\Permission instance for a given Authorizable & scope.

Creates new Permission in given scope & level and assigns it to a given Mrluke\Privileges\Contracts\Permitable. Note! Authorizable and Role implements the Permitable contract.

Determine if given Permitable has assigned scope permission.

Regains a Permission from Permitable.

Removes a Role from Authorizable.

Levels

There are 5 different Permission level that can by apply to Permitable. All of them with combination of multi-roles, personal permissions, restrictions and role's levels gives you a wide range of many possibilities but let's have a look on those 5:

Detector - Mrluke\Privileges\Detector

Detector is a main tool that provides an interface for detecting Authorizable privileges. There are 6 methods that can perform various check for you:

This method is responsible for belongsToMany scenario when two models are connected Many-to-many relation. By defult the name of function (relation) is detected from $model base class name (plural). In case you have your own convention of naming use parameter $relation to provide a function name.

This method is combination of has & level in row.

This method detects if Authorizable has assigned Permission by role or prsonal that satisfy the condition.

This method is responsible for hasOne and hasMany scenarion when Authorizable is an owner of model by flat relation. By default the foreign key is detecting from Authorizable base class name (with _id). In case you have a different key name use parameter $foreign to provide a foreign key's column name.

This method is combination of owner & level in row.

This method is responsible for a deeper relation scenario when Authorizable shares some model with a parent of $model. Let's imagine that you have a User that has many Thread which can have many Reply. Now you need to consider if it can rate Reply & only only an owner can do this. This is method for you.

Subject & Scope

Detector has two methods that are required as a predefinition. Befor any check you need to set a subject:

In case you want to detect level you need also to specife the scope by:

Examples

  1. Let's check if user can update all posts (level 4):

  2. Let's check if user is an owner or can update all posts (custom key):

Note! Manager & Detector are singleton instances.

Plans


All versions of privileges with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
laravel/framework Version ^8.0|^7.0|^6.0|^5.8
mr-luke/configuration Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mr-luke/privileges contains the following files

Loading the files please wait ....