Download the PHP package vsch/user-privilege-mapper without Composer

On this page you can find all versions of the php package vsch/user-privilege-mapper. 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 user-privilege-mapper

Laravel User Privilege Mapper

This package implements a simple Service Provider that enables mapping of user privileges independent of the implementation of the User model. It uses Laravel macros() to create an interface between a user privilege test and the actual implementation of the code to check whether the current user has this privilege enabled.

I use this package to allow my other packages to test for security privileges without having to dictate how the user model is defined within a project.

For Laravel 4 use the Laravel4 branch, or require: "vsch/user-privilege-mapper": "~1.0"

For Laravel 5 use the master branch, or require: "vsch/user-privilege-mapper": "~2.0"

Installation

  1. Require this package in your composer.json and run composer update (or run composer require vsch/user-privilege-mapper:* directly):

    "vsch/user-privilege-mapper": "~2.0"
  2. After updating composer, add the ServiceProviders to the providers array in config/app.php

    Vsch\UserPrivilegeMapper\UserPrivilegeMapperServiceProvider::class,
  3. add the Facade to the aliases array in config/app.php:

    'UserCan'   => Vsch\UserPrivilegeMapper\Facade\Privilege::class,
  4. To create a mapping layer between your User model implementation and the need to test user privileges without knowing the implementation. You need to create named privileges for the UserPrivilegeMapper via the Laravel macro mechanism. This should be done in the initialization files.

    A good place is the app/Providers/AppServiceProvider.php file, add the following to the boot() function, if your User model has is_admin and is_editor attributes to identify users that have Admin and Editor privileges or just return true in both cases, if you don't have any way of determining user privileges:

    \UserCan::macro("admin", function ()
    {
        return ($user = Auth::user()) && $user->is_admin;
    });
    
    \UserCan::macro("edit", function ()
    {
        return ($user = Auth::user()) && ($user->is_admin || $user->is_editor);
    });
  5. Testing whether a privilege is available is as simple as:

    if (\UserCan::admin())
    {
        // user has admin privileges
    }
    elseif (\UserCan::edit())
    {
        // user has edit privileges
    }

    If a macro was not previously defined then the privilege test will return false. Effectively, if the macro is not implemented then the privilege is treated as not existent for every user.

The implementation is more of a convention that is implemented by Laravel's Macroable trait. I don't see this package changing unless I get an epiphany. So consider this package code complete. However, suggestions are appreciated and welcome. :)


All versions of user-privilege-mapper with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version ~5.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 vsch/user-privilege-mapper contains the following files

Loading the files please wait ....