mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-21 19:34:54 +02:00
Used PHP_CS_Fixer with symfony preset on codebase.
This commit is contained in:
parent
0f3ba9b6a8
commit
e2f7aafa2d
43 changed files with 971 additions and 1068 deletions
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||
|
@ -26,7 +25,6 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -38,52 +36,48 @@ use Webmozart\Assert\Assert;
|
|||
* This entity represents the permission fields a user or group can have.
|
||||
*
|
||||
* @ORM\Embeddable()
|
||||
* @package App\Entity
|
||||
*/
|
||||
class PermissionsEmbed
|
||||
{
|
||||
/**
|
||||
* Permission values.
|
||||
*/
|
||||
public const INHERIT = 0b00;
|
||||
public const ALLOW = 0b01;
|
||||
public const DISALLOW = 0b10;
|
||||
|
||||
/**
|
||||
* Permission values
|
||||
* Permission strings.
|
||||
*/
|
||||
public const INHERIT = 0b00;
|
||||
public const ALLOW = 0b01;
|
||||
public const DISALLOW = 0b10;
|
||||
|
||||
|
||||
/**
|
||||
* Permission strings
|
||||
*/
|
||||
|
||||
public const STORELOCATIONS = 'storelocations';
|
||||
public const FOOTRPINTS = 'footprints';
|
||||
public const CATEGORIES = 'categories';
|
||||
public const SUPPLIERS = 'suppliers';
|
||||
public const MANUFACTURERS = 'manufacturers';
|
||||
public const DEVICES = 'devices';
|
||||
public const STORELOCATIONS = 'storelocations';
|
||||
public const FOOTRPINTS = 'footprints';
|
||||
public const CATEGORIES = 'categories';
|
||||
public const SUPPLIERS = 'suppliers';
|
||||
public const MANUFACTURERS = 'manufacturers';
|
||||
public const DEVICES = 'devices';
|
||||
public const ATTACHMENT_TYPES = 'attachment_types';
|
||||
public const TOOLS = 'tools';
|
||||
public const PARTS = 'parts';
|
||||
public const PARTS_NAME = 'parts_name';
|
||||
public const TOOLS = 'tools';
|
||||
public const PARTS = 'parts';
|
||||
public const PARTS_NAME = 'parts_name';
|
||||
public const PARTS_DESCRIPTION = 'parts_description';
|
||||
public const PARTS_INSTOCK = 'parts_instock';
|
||||
public const PARTS_MININSTOCK = 'parts_mininstock';
|
||||
public const PARTS_FOOTPRINT = 'parts_footprint';
|
||||
public const PARTS_COMMENT = 'parts_comment';
|
||||
public const PARTS_INSTOCK = 'parts_instock';
|
||||
public const PARTS_MININSTOCK = 'parts_mininstock';
|
||||
public const PARTS_FOOTPRINT = 'parts_footprint';
|
||||
public const PARTS_COMMENT = 'parts_comment';
|
||||
public const PARTS_STORELOCATION = 'parts_storelocation';
|
||||
public const PARTS_MANUFACTURER = 'parts_manufacturer';
|
||||
public const PARTS_ORDERDETAILS = 'parts_orderdetails';
|
||||
public const PARTS_PRICES = 'parts_prices';
|
||||
public const PARTS_PRICES = 'parts_prices';
|
||||
public const PARTS_ATTACHMENTS = 'parts_attachments';
|
||||
public const PARTS_ORDER = 'parts_order';
|
||||
public const GROUPS = 'groups';
|
||||
public const USERS = 'users';
|
||||
public const DATABASE = 'system_database';
|
||||
public const CONFIG = 'system_config';
|
||||
public const SYSTEM = 'system';
|
||||
public const DEVICE_PARTS = 'devices_parts';
|
||||
public const SELF = 'self';
|
||||
public const LABELS = 'labels';
|
||||
public const PARTS_ORDER = 'parts_order';
|
||||
public const GROUPS = 'groups';
|
||||
public const USERS = 'users';
|
||||
public const DATABASE = 'system_database';
|
||||
public const CONFIG = 'system_config';
|
||||
public const SYSTEM = 'system';
|
||||
public const DEVICE_PARTS = 'devices_parts';
|
||||
public const SELF = 'self';
|
||||
public const LABELS = 'labels';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
|
@ -259,14 +253,15 @@ class PermissionsEmbed
|
|||
*/
|
||||
protected $labels;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the bit pair value of the given permission.
|
||||
*
|
||||
* @param string $permission_name The name of the permission, for which the bit pair should be returned.
|
||||
* @param int $bit_n The (lower) bit number of the bit pair, which should be read.
|
||||
* @param int $bit_n The (lower) bit number of the bit pair, which should be read.
|
||||
*
|
||||
* @return int The value of the bit pair. Compare to the INHERIT, ALLOW, and DISALLOW consts in this class.
|
||||
*/
|
||||
public function getBitValue(string $permission_name, int $bit_n) : int
|
||||
public function getBitValue(string $permission_name, int $bit_n): int
|
||||
{
|
||||
$perm_int = $this->$permission_name;
|
||||
|
||||
|
@ -275,19 +270,21 @@ class PermissionsEmbed
|
|||
|
||||
/**
|
||||
* Returns the value of the operation for the given permission.
|
||||
*
|
||||
* @param string $permission_name The name of the permission, for which the operation should be returned.
|
||||
* @param int $bit_n The (lower) bit number of the bit pair for the operation.
|
||||
* @param int $bit_n The (lower) bit number of the bit pair for the operation.
|
||||
*
|
||||
* @return bool|null The value of the operation. True, if the given operation is allowed, false if disallowed
|
||||
* and null if it should inherit from parent.
|
||||
* and null if it should inherit from parent.
|
||||
*/
|
||||
public function getPermissionValue(string $permission_name, int $bit_n) : ?bool
|
||||
public function getPermissionValue(string $permission_name, int $bit_n): ?bool
|
||||
{
|
||||
$value = $this->getBitValue($permission_name, $bit_n);
|
||||
if ($value == self::ALLOW) {
|
||||
if (self::ALLOW == $value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if($value == self::DISALLOW) {
|
||||
if (self::DISALLOW == $value) {
|
||||
return false;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -296,14 +293,16 @@ class PermissionsEmbed
|
|||
|
||||
/**
|
||||
* Reads a bit pair from $data.
|
||||
*
|
||||
* @param $data int The data from where the bits should be extracted from.
|
||||
* @param $n int The number of the lower bit (of the pair) that should be read. Starting from zero.
|
||||
*
|
||||
* @return int The value of the bit pair.
|
||||
*/
|
||||
final protected static function readBitPair(int $data, int $n): int
|
||||
{
|
||||
Assert::lessThanEq($n,31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
|
||||
if ($n % 2 !== 0) {
|
||||
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
|
||||
if (0 !== $n % 2) {
|
||||
throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
|
||||
}
|
||||
|
||||
|
@ -313,24 +312,26 @@ class PermissionsEmbed
|
|||
|
||||
/**
|
||||
* Writes a bit pair in the given $data and returns it.
|
||||
*
|
||||
* @param $data int The data which should be modified.
|
||||
* @param $n int The number of the lower bit of the pair which should be written.
|
||||
* @param $new int The new value of the pair.
|
||||
*
|
||||
* @return int The new data with the modified pair.
|
||||
*/
|
||||
final protected static function writeBitPair(int $data, int $n, int $new) : int
|
||||
final protected static function writeBitPair(int $data, int $n, int $new): int
|
||||
{
|
||||
Assert::lessThanEq($n,31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
|
||||
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
|
||||
Assert::lessThanEq($new, 3, '$new must be smaller than 3, because a bit pair is written! Got %s.');
|
||||
|
||||
if ($n % 2 !== 0) {
|
||||
if (0 !== $n % 2) {
|
||||
throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
|
||||
}
|
||||
|
||||
$mask = 0b11 << $n; //Mask all bits that should be writen
|
||||
$newval = $new << $n; //The new value.
|
||||
$data = ($data & ~$mask) | ($newval & $mask);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue