Download the PHP package rookwood/turnstile without Composer

On this page you can find all versions of the php package rookwood/turnstile. 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 turnstile

Turnstile

Turnstile is a policy-based ACL library for Laravel 4 designed to give very fine-grained control over user permissions. This is accomplished by mapping any given user action to a policy class that evaluates if the action is allowable. Doing such allows for more control than a simple user/role system (though roles are still easily used in Turnstile). The beauty of this is that the same system can be used for everything from protecting an admin panel to checking if a user can see a login button (if already logged in, just deny access for visibility, etc).

Example

Since no one has ever used a blog example before, we'll do that here:

``

The edit_comment action is mapped to a policy class via a PolicyProvider. For edit_comment, we map to CommentEditingPolicy for this example.

``

As you see, you can have a policy deny permission for any number of reasons and provide a specific error stating why. I like to use class constants to hold message keys that I can later feed to Lang::get() for an actual, clean message. Added benefit: ease of translation.

Installation

1: Grab everything via composer

`

2: Add Rookwood\Turnstile\TurnstileServiceProvider to the list of service providers in app/config/app.php

3: Publish configuration and run migrations. Note that your users table migration must be run before the role_user pivot table can be created. It is dated sufficiently far enough into the future that this shouldn't be a problem as long as you have already created the migration file for your users table.

`

4: Create your PolicyProvider file (can be put anywhere as long as the autoloader can find it).

``

5: Edit your config/packages/rookwood/turnstile/turnstile.php to have the namespace key point to your provider's namespace. That's how the PolicyServiceProvider class will know where to find it.

6: Have your User model use the Rookwood\Turnstile\User\PolicyTrait.

7: Make sure that any controller necessary has access to the current user object. I usually do it via the constructor like thus:

``

8: In app/config/app.php add an alias for Role to Rookwood\Turnstile\User\Role. As an alternative, you can create your own Role class as long as you have a m:n relationship with your User class. If your User class is namespaced, do the same for it.

Usage

Now that you've done all the set-up, actually using this is fairly easy. Any time you want to see if the user is allowed to do something, you just call $user->can('do_something', array('someData' => 'data needed for evaluation')). This will return a boolean. If it's False, you can get the status code sent by the policy at Rookwood\Turnstile\Policies\Policy::$policyFailureState. Probably makes sense to import that namespace and have a separate method or class to deal with failures. Depending on what the user was trying to do, it might even make sense to set a 403 NOT AUTHORIZED on the response header. Obviously this makes more sense for actions trying to access a sensitive area of the site vs checking to see if the user can see a registration link.

Then you just create your policy class with the execute method and have it return either TRUE or an error status (see example above). Add the action name and policy class to the PolicyProvider, and you're good to go.

The PolicyTrait included for your User model provides a few useful methods to help your policy classes and user roles:

`` Test if a relationship exists between the user and the provided object in the database:

` Test if a user has a particular role.isAn()is also available for people like me who would frown at something likeisA('admin')`:

` Add a role to a user. Can pass either a string of the role name or a role object.removeRole($role)` is also available.


All versions of turnstile with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version 4.2.*
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 rookwood/turnstile contains the following files

Loading the files please wait ....