PHPackages                             trejjam/authorization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. trejjam/authorization

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

trejjam/authorization
=====================

Authorization, Authentication, Acl

v0.10.1(10y ago)0862MITPHPPHP &gt;=5.4

Since Dec 16Pushed 10y ago1 watchersCompare

[ Source](https://github.com/trejjam/Authorization)[ Packagist](https://packagist.org/packages/trejjam/authorization)[ RSS](/packages/trejjam-authorization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (11)Versions (17)Used By (0)

Authorization
=============

[](#authorization)

[![Latest stable](https://camo.githubusercontent.com/ff062ffd024d37c436ac1774f144adc4a93c797040088e4ae678f4ec1260b8b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7472656a6a616d2f617574686f72697a6174696f6e2e737667)](https://packagist.org/packages/trejjam/authorization)

Library for

- authorization
- roles
- resource

in \[Nette\]() using database Installation
------------

[](#installation)

The best way to install Trejjam/Authorization is using [Composer](http://getcomposer.org/):

```
$ composer require trejjam/authorization
```

Configuration
-------------

[](#configuration)

.neon

```
extensions:
	authorization: Trejjam\Authorization\DI\AuthorizationExtension

authorization:
	tables:
		users:
			table	 : users__users
			id	    : id #column name
			status    :
				accept : enable
				options:
					enable
					disable
			activated :
				accept: yes
				options:
					yes
					no
			username  :
				match  : '/^[a-zA-Z_]+$/' #email is special value (validate by Nette\Utils\Validators:isEmail)
				length : 60
			items:
				- id
				- status
				- activated
				- username
				- password
				dateCreated: date_created
		roles:
			table    : users__roles
			id       : id #column name
			parentId : parent_id #column name, foreign key to role.id
			roleName : name #column name
			info     : info #column name, value FALSE disable usage
		userRoles:
			table  : users__user_role
			id     : id #column name
			userId : user_id #column name, foreign key to users.id
			roleId : role_id #column name, foreign key to roles.id
		resource :
			table          : users__resources
			id             : id #column name
			roleId         : role_id #column name, foreign key to role.id
			resourceName   : name #column name
			resourceAction : action #column name, default ALL
	reloadChangedUser: true
	cache :
		use     : true
		name    : authorization
		timeout : 10 minutes
	debugger:false #not implemented yet

services:
	- Browser
```

Config
------

[](#config)

The best way for configuration is using [Kdyby/Console](https://github.com/kdyby/console)

```
$ composer require kdyby/console
```

Read how to install [Kdyby/Console](https://github.com/Kdyby/Console/blob/master/docs/en/index.md)

```
php index.php
```

After successful installation display:

```
Available commands:
Auth
	Auth:install    Install default tables
	Auth:resource   Edit resource
	Auth:role       Edit role
	Auth:user       Edit user
	help            Displays help for a command
	list            Lists commands

```

Config database
---------------

[](#config-database)

Create default tables:

```
php index.php Auth:install
```

Config role
-----------

[](#config-role)

Add role:

```
php index.php Auth:role -c [-r] roleName [parentRole [info]]
```

Move role to other parent:

```
php index.php Auth:role -m [-r] roleName [parentRole]
```

Delete role: options -f delete all child roles and their resource

```
php index.php Auth:role -d [-f] roleName
```

List all role:

```
php index.php Auth:role -r
```

Config resource
---------------

[](#config-resource)

Add resource:

```
php index.php Auth:resource -c [-r] resourceName[:resourceAction] parentRole
```

Move resource to other role:

```
php index.php Auth:resource -m [-r] resourceName[:resourceAction] parentRole
```

Delete resource:

```
php index.php Auth:resource -d resourceName[:resourceAction]
```

List all resource:

```
php index.php Auth:resource -r
```

Config user
-----------

[](#config-user)

Add user:

```
php index.php Auth:user -c username password
```

Change password:

```
php index.php Auth:user -p username password
```

Set user status:

```
php index.php Auth:user -s status username
```

default status values \[enable|disable\]

Set user activated:

```
php index.php Auth:user -a activated username
```

default activated values \[yes|no\]

Show user roles:

```
php index.php Auth:user -r username
```

Add user role:

```
php index.php Auth:user [-r] -t roleName username
```

Remove user role:

```
php index.php Auth:user [-r] -d roleName username
```

Usage
-----

[](#usage)

Presenter:

```
	/**
	* @var \Trejjam\Authorization\Acl @inject
	*/
	public $acl;
	/**
	* @var \Trejjam\Authorization\UserManager @inject
	*/
	public $userManager;
	/**
	* @var \Trejjam\Authorization\UserRequest @inject
	*/
	public $userRequest;

	function renderDefault() {
		dump($this->acl->getTrees()->getRootRoles()); //get all roles without parent
		dump($this->acl->getTrees()->getRoles()); //get all roles
		dump($this->acl->getTrees()->getResources()); //get all resource

		$this->acl->createRole($name, $parent, $info);
		$this->acl->deleteRole($name);
		$this->acl->moveRole($name, $parent);

		dump($this->acl->getRoleByName($roleName)); //return AclRole with "name"

		$this->acl->createResource($name, $action, $roleName);
        $this->acl->deleteResource($name, $action);
        $this->acl->moveResource($name, $action, $roleName);

        dump($this->acl->getResourceById($id)); //return AclResource

        dump($this->acl->getUserRoles($userId)); //return AclRole[]
        $this->acl->addUserRole($userId, $roleName);
        $this->acl->removeUserRole($userId, $roleName);

        //--------------userManager--------------

        $this->userManager->add($username, $password);
        $this->userManager->changePassword($username, $password, $type = "username"); //$type could be username|id
        $this->userManager->setUpdated($username, $type = "username"); //next user request user session will be reload (if "reloadChangedUser: true")
        $this->userManager->setStatus($username, $status, $type = "username"); //$status could be enable|disable - if user with disable status try login, login function return exception
        $this->userManager->setActivated($username, $activated = NULL, $type = "username"); //$activated could be yes|no - if user with 'no' activated try login, login function return exception
        dump($this->userManager->getUserId($username)); //return id of user
        $this->userManager->getUserInfo($username, $type = "auto"); //return all information about user except password
        $this->userManager->getUsersList(); //return getUserInfo[] for all users

        //--------------userRequest--------------

        dump($this->userRequest->generateHash($userId, $type)); //return hash for public usage, $type could be activate|lostPassword
        dump($this->userRequest->getType($userId, $hash, $invalidateHash = FALSE)); //return TRUE - hash was used|$type|FALSE - user hasn't this hash, $invalidateHash=TRUE - disable future hash usage
	}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Recently: every ~52 days

Total

16

Last Release

3885d ago

PHP version history (2 changes)v0.4PHP &gt;=5.3.1

v0.10.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/497b0b5c3df7d9a3a4349ccd81b47db5b6027fc7d49510a04265dd966d01f846?d=identicon)[trejjam](/maintainers/trejjam)

---

Top Contributors

[![trejjam](https://avatars.githubusercontent.com/u/3594540?v=4)](https://github.com/trejjam "trejjam (85 commits)")

---

Tags

netteAuthenticationauthorizationacl

### Embed Badge

![Health badge](/badges/trejjam-authorization/health.svg)

```
[![Health](https://phpackages.com/badges/trejjam-authorization/health.svg)](https://phpackages.com/packages/trejjam-authorization)
```

###  Alternatives

[nette/security

🔑 Nette Security: provides authentication, authorization and a role-based access control management via ACL (Access Control List)

3839.3M279](/packages/nette-security)[pktharindu/nova-permissions

Laravel Nova Grouped Permissions (ACL)

136387.1k](/packages/pktharindu-nova-permissions)[dereuromark/cakephp-tinyauth

A CakePHP plugin to handle user authentication and authorization the easy way.

129228.6k10](/packages/dereuromark-cakephp-tinyauth)[silvanite/novatoolpermissions

Laravel Nova Permissions (Roles and Permission based Access Control (ACL))

100256.7k2](/packages/silvanite-novatoolpermissions)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)[efficiently/authority-controller

AuthorityController is an PHP authorization library for Laravel 5 which restricts what resources a given user is allowed to access.

15533.2k](/packages/efficiently-authority-controller)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
