pull out permission to framework

This commit is contained in:
Dennis Eichhorn 2017-09-14 10:18:01 +02:00
parent c608caa0e2
commit cb0a443c55
2 changed files with 158 additions and 0 deletions

View File

@ -207,6 +207,28 @@ class Account implements ArrayableInterface, \JsonSerializable
$this->l11n = $l11n;
}
public function setPermissions(array $permissions) /* : void */
{
$this->permissions = $permissions;
}
public function hasPermission(int $permission, int $unit = null, string $app = null, int $module = null, int $type = null, $element = null, $component = null) : bool
{
foreach($this->permissions as $p) {
if(($p->getUnit() === $unit || $p->getUnit() === null)
&& ($p->getApp() === $app || $p->getApp() === null)
&& ($p->getModule() === $module || $p->getModule() === null)
&& ($p->getType() === $type || $p->getType() === null)
&& ($p->getElement() === $element || $p->getElement() === null)
&& ($p->getComponent() === $component || $p->getComponent() === null)
&& ($p->getPermission() | $permission) === $p->getPermission()) {
return true;
}
}
return false;
}
/**
* Get name.
*

View File

@ -0,0 +1,136 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace phpOMS\Account;
/**
* InfoManager class.
*
* Handling the info files for modules
*
* @category Framework
* @package phpOMS\Module
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class PermissionAbstract
{
protected $id = 0;
protected $unit = null;
protected $app = null;
protected $module = null;
protected $from = 0;
protected $type = null;
protected $element = null;
protected $component = null;
protected $permission = 0;
public function getId()
{
return $id;
}
public function getUnit()
{
return $this->unit;
}
public function getApp()
{
return $this->app;
}
public function getModule()
{
return $this->module;
}
public function getFrom()
{
return $this->from;
}
public function getType()
{
return $this->type;
}
public function getElement()
{
return $this->element;
}
public function getComponent()
{
return $this->component;
}
public function getPermission() : int
{
return $this->permission;
}
public function setUnit(int $unit = null) /* : void */
{
$this->unit = $unit;
}
public function setApp(int $app = null) /* : void */
{
$this->app = $app;
}
public function setModule(int $module = null) /* : void */
{
$this->module = $module;
}
public function setFrom(int $from = null) /* : void */
{
$this->from = $from;
}
public function setType(int $type = null) /* : void */
{
$this->type = $type;
}
public function setElement(int $element = null) /* : void */
{
$this->element = $element;
}
public function setComponent(int $component = null) /* : void */
{
$this->component = $component;
}
public function setPermission(int $permission = 0) /* : void */
{
if($permission === 0) {
$this->permission = 0;
} else {
$this->permission |= $permission;
}
}
}