2023-07-29 03:17:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the area security information
|
|
|
|
*/
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
trait AreaSecurity
|
|
|
|
{
|
2024-04-14 11:16:33 +00:00
|
|
|
/**
|
|
|
|
* Does the security level provide read or write access
|
|
|
|
*
|
|
|
|
* @param int $sec
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function can_access(int $sec): bool
|
|
|
|
{
|
|
|
|
return $this->can_read($sec) || $this->can_write($sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the security level provide read access
|
|
|
|
*
|
|
|
|
* @param int $sec
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function can_read(int $sec): bool
|
|
|
|
{
|
|
|
|
return $this->active && (($sec >= ($x=$this->getSecReadAttribute())) && $x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the security level provide write access
|
|
|
|
*
|
|
|
|
* @param int $sec
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function can_write(int $sec): bool
|
|
|
|
{
|
|
|
|
return $this->active && (($sec >= ($x=$this->getSecWriteAttribute())) && $x);
|
|
|
|
}
|
|
|
|
|
2023-07-29 03:17:36 +00:00
|
|
|
public function getSecReadAttribute(): int
|
|
|
|
{
|
|
|
|
return ($this->security>>3) & 0x7;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecWriteAttribute(): int
|
|
|
|
{
|
|
|
|
return $this->security & 0x7;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRead(int $security): void
|
|
|
|
{
|
|
|
|
$this->security = ($this->security & ~(0x7<<3)) | (($security & 0x7) << 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setWrite(int $security): void
|
|
|
|
{
|
|
|
|
$this->security = ($this->security & ~(0x7)) | ($security & 0x7);
|
|
|
|
}
|
|
|
|
}
|